Skip to content

Commit

Permalink
adding inventory collection for Cisco IOS devices
Browse files Browse the repository at this point in the history
  • Loading branch information
maccioni committed Dec 20, 2017
1 parent 176d2a0 commit e0b576d
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,45 @@ n9k5 : ok=1 changed=0 unreachable=0 failed=0
n9k6 : ok=1 changed=0 unreachable=0 failed=0
```

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)

```
[root@localhost ansible_inventory_report]# ansible-playbook inventory-ios.yml
PLAY [build IOS XE inventory] **************************************************************
TASK [gathering IOS XE facts] **************************************************************
ok: [172.26.249.162]
ok: [172.26.249.161]
ok: [172.26.249.164]
ok: [172.26.249.163]
ok: [172.26.249.160]
ok: [172.26.249.151]
ok: [172.26.249.166]
ok: [172.26.249.153]
ok: [172.26.249.169]
ok: [172.26.249.152]
ok: [172.26.249.154]
ok: [172.26.249.159]
TASK [create HTML report] ******************************************************************
changed: [172.26.249.160 -> localhost]
PLAY RECAP *********************************************************************************
172.26.249.151 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.152 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.153 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.154 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.159 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.160 : ok=2 changed=1 unreachable=0 failed=0
172.26.249.161 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.162 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.163 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.164 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.166 : ok=1 changed=0 unreachable=0 failed=0
172.26.249.169 : ok=1 changed=0 unreachable=0 failed=0
```

---
![Ansible Red Hat Engine](ansible-engine-small.png)

Expand Down
14 changes: 14 additions & 0 deletions hosts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
localhost

[ios]
172.26.249.160
172.26.249.161
172.26.249.162
172.26.249.163
172.26.249.164
172.26.249.166
172.26.249.169
172.26.249.151
172.26.249.152
172.26.249.153
172.26.249.154
172.26.249.159

[mac]
192.168.2.1

Expand Down
22 changes: 22 additions & 0 deletions inventory-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: build IOS XE inventory
hosts: ios
connection: local
gather_facts: False

vars:
desired_ios_version: "16.06.01"

tasks:

- name: gathering IOS XE facts
ios_facts:
register: all_facts

- name: create HTML report
template:
src: report-ios.j2
dest: /var/www/html/inventory_report_ios.html
delegate_to: localhost
run_once: true
# provider: "{{login_info}}"
106 changes: 106 additions & 0 deletions inventory_report_ios.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<table>
<thead>
<tr>
<th>Hostname</th>
<th>Model Type</th>
<th>Serial Number</th>
<th>Mgmt interface IP</th>
<th>Code Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>cat3k-160</td>
<td></td>
<td>FCW2023D16V</td>
<td>172.26.249.160</td>
<td >16.06.01</td>
</tr>
<tr>
<td>cat3k-161</td>
<td></td>
<td>FCW2023C1K1</td>
<td>172.26.249.161</td>
<td >16.06.01</td>
</tr>
<tr>
<td>cat3k-162</td>
<td></td>
<td>FOC2020U0X0</td>
<td>172.26.249.162</td>
<td >16.06.01</td>
</tr>
<tr>
<td>cat3k-163</td>
<td></td>
<td>FCW2023D17F</td>
<td>172.26.249.163</td>
<td >16.06.01</td>
</tr>
<tr>
<td>cat3k-164</td>
<td></td>
<td>FOC1949U1JA</td>
<td>172.26.249.164</td>
<td >16.06.01</td>
</tr>
<tr>
<td>cat3k-166</td>
<td></td>
<td>FCW1949D16M</td>
<td>172.26.249.166</td>
<td >16.06.01</td>
</tr>
<tr>
<td>cat3k-169</td>
<td></td>
<td>FOC1731V1QZ</td>
<td>172.26.249.169</td>
<td >16.06.01</td>
</tr>
<tr>
<td>cat9k-1</td>
<td></td>
<td>FCW2125L0N7</td>
<td>172.26.249.151</td>
<td style="background:yellow;">BLD_POLARIS_DEV_LATEST_20171031_020522</td>
</tr>
<tr>
<td>cat9k-2</td>
<td></td>
<td>FCW2125L0M9</td>
<td>172.26.249.152</td>
<td style="background:yellow;">BLD_POLARIS_DEV_LATEST_20171031_020522</td>
</tr>
<tr>
<td>cat9k-3</td>
<td></td>
<td>FCW2125G06X</td>
<td>172.26.249.153</td>
<td style="background:yellow;">BLD_POLARIS_DEV_LATEST_20171031_020522</td>
</tr>
<tr>
<td>cat9k-4</td>
<td></td>
<td>FCW2125L0J2</td>
<td>172.26.249.154</td>
<td style="background:yellow;">BLD_POLARIS_DEV_LATEST_20171031_020522</td>
</tr>
<tr>
<td>cat9k-puppet</td>
<td></td>
<td>FCW2122A4H0</td>
<td>172.26.249.159</td>
<td style="background:yellow;">2017-10-04_23.58_petervh</td>
</tr>
</tbody>
</table>

</body>
</html>
31 changes: 31 additions & 0 deletions report-ios.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<table>
<thead>
<tr>
<th>Hostname</th>
<th>Model Type</th>
<th>Serial Number</th>
<th>Mgmt interface IP</th>
<th>Code Version</th>
</tr>
</thead>
<tbody>
{% for network_switch in groups['ios'] %}
<tr>
<td>{{hostvars[network_switch]['ansible_net_hostname']}}</td>
<td>{{hostvars[network_switch]['ansible_net_model']}}</td>
<td>{{hostvars[network_switch]['ansible_net_serialnum']}}</td>
<td>{{hostvars[network_switch]['ansible_net_interfaces']['GigabitEthernet0/0']['ipv4'][0]['address']}}</td>
<td {% if hostvars[network_switch]['ansible_net_version'] != desired_ios_version %}style="background:yellow;"{% endif %}>{{hostvars[network_switch]['ansible_net_version']}}</td>
</tr>
{% endfor %}
</tbody>
</table>

</body>
</html>

0 comments on commit e0b576d

Please sign in to comment.