File tree Expand file tree Collapse file tree 5 files changed +212
-0
lines changed Expand file tree Collapse file tree 5 files changed +212
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,45 @@ n9k5 : ok=1 changed=0 unreachable=0 failed=0
53
53
n9k6 : ok=1 changed=0 unreachable=0 failed=0
54
54
```
55
55
56
+ A very similar playbook can be used to generate a report for Cisco IOS devices using the [ ios_facts module] ( http://docs.ansible.com/ansible/latest/ios_facts_module.html )
57
+
58
+ ```
59
+ [root@localhost ansible_inventory_report]# ansible-playbook inventory-ios.yml
60
+
61
+ PLAY [build IOS XE inventory] **************************************************************
62
+
63
+ TASK [gathering IOS XE facts] **************************************************************
64
+ ok: [172.26.249.162]
65
+ ok: [172.26.249.161]
66
+ ok: [172.26.249.164]
67
+ ok: [172.26.249.163]
68
+ ok: [172.26.249.160]
69
+ ok: [172.26.249.151]
70
+ ok: [172.26.249.166]
71
+ ok: [172.26.249.153]
72
+ ok: [172.26.249.169]
73
+ ok: [172.26.249.152]
74
+ ok: [172.26.249.154]
75
+ ok: [172.26.249.159]
76
+
77
+ TASK [create HTML report] ******************************************************************
78
+ changed: [172.26.249.160 -> localhost]
79
+
80
+ PLAY RECAP *********************************************************************************
81
+ 172.26.249.151 : ok=1 changed=0 unreachable=0 failed=0
82
+ 172.26.249.152 : ok=1 changed=0 unreachable=0 failed=0
83
+ 172.26.249.153 : ok=1 changed=0 unreachable=0 failed=0
84
+ 172.26.249.154 : ok=1 changed=0 unreachable=0 failed=0
85
+ 172.26.249.159 : ok=1 changed=0 unreachable=0 failed=0
86
+ 172.26.249.160 : ok=2 changed=1 unreachable=0 failed=0
87
+ 172.26.249.161 : ok=1 changed=0 unreachable=0 failed=0
88
+ 172.26.249.162 : ok=1 changed=0 unreachable=0 failed=0
89
+ 172.26.249.163 : ok=1 changed=0 unreachable=0 failed=0
90
+ 172.26.249.164 : ok=1 changed=0 unreachable=0 failed=0
91
+ 172.26.249.166 : ok=1 changed=0 unreachable=0 failed=0
92
+ 172.26.249.169 : ok=1 changed=0 unreachable=0 failed=0
93
+ ```
94
+
56
95
---
57
96
![ Ansible Red Hat Engine] ( ansible-engine-small.png )
58
97
Original file line number Diff line number Diff line change 1
1
localhost
2
2
3
+ [ios]
4
+ 172.26.249.160
5
+ 172.26.249.161
6
+ 172.26.249.162
7
+ 172.26.249.163
8
+ 172.26.249.164
9
+ 172.26.249.166
10
+ 172.26.249.169
11
+ 172.26.249.151
12
+ 172.26.249.152
13
+ 172.26.249.153
14
+ 172.26.249.154
15
+ 172.26.249.159
16
+
3
17
[mac]
4
18
192.168.2.1
5
19
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : build IOS XE inventory
3
+ hosts : ios
4
+ connection : local
5
+ gather_facts : False
6
+
7
+ vars :
8
+ desired_ios_version : " 16.06.01"
9
+
10
+ tasks :
11
+
12
+ - name : gathering IOS XE facts
13
+ ios_facts :
14
+ register : all_facts
15
+
16
+ - name : create HTML report
17
+ template :
18
+ src : report-ios.j2
19
+ dest : /var/www/html/inventory_report_ios.html
20
+ delegate_to : localhost
21
+ run_once : true
22
+ # provider: "{{login_info}}"
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < link rel ="stylesheet " href ="css/main.css ">
5
+ </ head >
6
+ < body >
7
+ < table >
8
+ < thead >
9
+ < tr >
10
+ < th > Hostname</ th >
11
+ < th > Model Type</ th >
12
+ < th > Serial Number</ th >
13
+ < th > Mgmt interface IP</ th >
14
+ < th > Code Version</ th >
15
+ </ tr >
16
+ </ thead >
17
+ < tbody >
18
+ < tr >
19
+ < td > cat3k-160</ td >
20
+ < td > </ td >
21
+ < td > FCW2023D16V</ td >
22
+ < td > 172.26.249.160</ td >
23
+ < td > 16.06.01</ td >
24
+ </ tr >
25
+ < tr >
26
+ < td > cat3k-161</ td >
27
+ < td > </ td >
28
+ < td > FCW2023C1K1</ td >
29
+ < td > 172.26.249.161</ td >
30
+ < td > 16.06.01</ td >
31
+ </ tr >
32
+ < tr >
33
+ < td > cat3k-162</ td >
34
+ < td > </ td >
35
+ < td > FOC2020U0X0</ td >
36
+ < td > 172.26.249.162</ td >
37
+ < td > 16.06.01</ td >
38
+ </ tr >
39
+ < tr >
40
+ < td > cat3k-163</ td >
41
+ < td > </ td >
42
+ < td > FCW2023D17F</ td >
43
+ < td > 172.26.249.163</ td >
44
+ < td > 16.06.01</ td >
45
+ </ tr >
46
+ < tr >
47
+ < td > cat3k-164</ td >
48
+ < td > </ td >
49
+ < td > FOC1949U1JA</ td >
50
+ < td > 172.26.249.164</ td >
51
+ < td > 16.06.01</ td >
52
+ </ tr >
53
+ < tr >
54
+ < td > cat3k-166</ td >
55
+ < td > </ td >
56
+ < td > FCW1949D16M</ td >
57
+ < td > 172.26.249.166</ td >
58
+ < td > 16.06.01</ td >
59
+ </ tr >
60
+ < tr >
61
+ < td > cat3k-169</ td >
62
+ < td > </ td >
63
+ < td > FOC1731V1QZ</ td >
64
+ < td > 172.26.249.169</ td >
65
+ < td > 16.06.01</ td >
66
+ </ tr >
67
+ < tr >
68
+ < td > cat9k-1</ td >
69
+ < td > </ td >
70
+ < td > FCW2125L0N7</ td >
71
+ < td > 172.26.249.151</ td >
72
+ < td style ="background:yellow; "> BLD_POLARIS_DEV_LATEST_20171031_020522</ td >
73
+ </ tr >
74
+ < tr >
75
+ < td > cat9k-2</ td >
76
+ < td > </ td >
77
+ < td > FCW2125L0M9</ td >
78
+ < td > 172.26.249.152</ td >
79
+ < td style ="background:yellow; "> BLD_POLARIS_DEV_LATEST_20171031_020522</ td >
80
+ </ tr >
81
+ < tr >
82
+ < td > cat9k-3</ td >
83
+ < td > </ td >
84
+ < td > FCW2125G06X</ td >
85
+ < td > 172.26.249.153</ td >
86
+ < td style ="background:yellow; "> BLD_POLARIS_DEV_LATEST_20171031_020522</ td >
87
+ </ tr >
88
+ < tr >
89
+ < td > cat9k-4</ td >
90
+ < td > </ td >
91
+ < td > FCW2125L0J2</ td >
92
+ < td > 172.26.249.154</ td >
93
+ < td style ="background:yellow; "> BLD_POLARIS_DEV_LATEST_20171031_020522</ td >
94
+ </ tr >
95
+ < tr >
96
+ < td > cat9k-puppet</ td >
97
+ < td > </ td >
98
+ < td > FCW2122A4H0</ td >
99
+ < td > 172.26.249.159</ td >
100
+ < td style ="background:yellow; "> 2017-10-04_23.58_petervh</ td >
101
+ </ tr >
102
+ </ tbody >
103
+ </ table >
104
+
105
+ </ body >
106
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ <html >
3
+ <head >
4
+ <link rel =" stylesheet" href =" css/main.css" >
5
+ </head >
6
+ <body >
7
+ <table >
8
+ <thead >
9
+ <tr >
10
+ <th >Hostname</th >
11
+ <th >Model Type</th >
12
+ <th >Serial Number</th >
13
+ <th >Mgmt interface IP</th >
14
+ <th >Code Version</th >
15
+ </tr >
16
+ </thead >
17
+ <tbody >
18
+ {% for network_switch in groups ['ios' ] %}
19
+ <tr >
20
+ <td >{{hostvars[network_switch] ['ansible_net_hostname'] }}</td >
21
+ <td >{{hostvars[network_switch] ['ansible_net_model'] }}</td >
22
+ <td >{{hostvars[network_switch] ['ansible_net_serialnum'] }}</td >
23
+ <td >{{hostvars[network_switch] ['ansible_net_interfaces'] ['GigabitEthernet0/0'] ['ipv4'] [0] ['address'] }}</td >
24
+ <td {% if hostvars[network_switch][ ' ansible_net_version' ] ! = desired_ios_version %}style =" background:yellow;" {% endif %} >{{hostvars[network_switch] ['ansible_net_version'] }}</td >
25
+ </tr >
26
+ {% endfor %}
27
+ </tbody >
28
+ </table >
29
+
30
+ </body >
31
+ </html >
You can’t perform that action at this time.
0 commit comments