diff --git a/README.md b/README.md index 28195f6..2e41abc 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/hosts b/hosts index 802ef46..be95bcc 100644 --- a/hosts +++ b/hosts @@ -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 diff --git a/inventory-ios.yml b/inventory-ios.yml new file mode 100644 index 0000000..9eb5f64 --- /dev/null +++ b/inventory-ios.yml @@ -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}}" diff --git a/inventory_report_ios.html b/inventory_report_ios.html new file mode 100644 index 0000000..2bcd324 --- /dev/null +++ b/inventory_report_ios.html @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
HostnameModel TypeSerial NumberMgmt interface IPCode Version
cat3k-160FCW2023D16V172.26.249.16016.06.01
cat3k-161FCW2023C1K1172.26.249.16116.06.01
cat3k-162FOC2020U0X0172.26.249.16216.06.01
cat3k-163FCW2023D17F172.26.249.16316.06.01
cat3k-164FOC1949U1JA172.26.249.16416.06.01
cat3k-166FCW1949D16M172.26.249.16616.06.01
cat3k-169FOC1731V1QZ172.26.249.16916.06.01
cat9k-1FCW2125L0N7172.26.249.151BLD_POLARIS_DEV_LATEST_20171031_020522
cat9k-2FCW2125L0M9172.26.249.152BLD_POLARIS_DEV_LATEST_20171031_020522
cat9k-3FCW2125G06X172.26.249.153BLD_POLARIS_DEV_LATEST_20171031_020522
cat9k-4FCW2125L0J2172.26.249.154BLD_POLARIS_DEV_LATEST_20171031_020522
cat9k-puppetFCW2122A4H0172.26.249.1592017-10-04_23.58_petervh
+ + + diff --git a/report-ios.j2 b/report-ios.j2 new file mode 100644 index 0000000..2dfbf0b --- /dev/null +++ b/report-ios.j2 @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + +{% for network_switch in groups['ios'] %} + + + + + + + +{% endfor %} + +
HostnameModel TypeSerial NumberMgmt interface IPCode Version
{{hostvars[network_switch]['ansible_net_hostname']}}{{hostvars[network_switch]['ansible_net_model']}}{{hostvars[network_switch]['ansible_net_serialnum']}}{{hostvars[network_switch]['ansible_net_interfaces']['GigabitEthernet0/0']['ipv4'][0]['address']}}{{hostvars[network_switch]['ansible_net_version']}}
+ + +