Giter VIP home page Giter VIP logo

network-automation / ansible_inventory_report Goto Github PK

View Code? Open in Web Editor NEW
129.0 18.0 76.0 375 KB

This repo contains an Ansible networking inventory report playbook (inventory.yml). This playbook exports hostname, platform, mgmt0 IP address and code version to a HTML file. The jinja2 template used for the website can also highlight the version of code if it doesn't match a desired version.

License: Other

CSS 22.05% HTML 77.95%
ansible nxos playbook

ansible_inventory_report's Introduction

Example of Networking Inventory with Ansible

One of the many use cases for Ansible and the networking modules is to grab information in real time from the network. In this example I will generate a HTML report using the template module from facts I have gathered with the nxos_facts module. HTML report generated by template module

The playbook

Only two modules are needed for this example. The nxos_facts module and the template module

---
- name: build NXOS inventory report
  hosts: nxos
  connection: network_cli
  gather_facts: False

  vars:
    desired_version: "7.0(3)I7(1)"
    file_path: /var/www/html/generated_report.html

  tasks:
    - name: gathering nxos facts
      nxos_facts:
        provider: "{{login_info}}"
      register: all_facts

    - name: create HTML report
      template:
        src: report.j2
        dest: "{{ file_path }}"
      delegate_to: localhost
      run_once: true

Running the playbook

Use the ansible-playbook command:

[root@localhost ansible_inventory_report]# ansible-playbook inventory.yml

PLAY [cisco] ******************************************************************

TASK [gathering nxos facts] ***************************************************
ok: [n9k3]
ok: [n9k4]
ok: [n9k5]
ok: [n9k2]
ok: [n9k]
ok: [n9k6]

TASK [create HTML report] *****************************************************
changed: [n9k -> localhost]

PLAY RECAP ********************************************************************
n9k                        : ok=2    changed=1    unreachable=0    failed=0
n9k2                       : ok=1    changed=0    unreachable=0    failed=0
n9k3                       : ok=1    changed=0    unreachable=0    failed=0
n9k4                       : ok=1    changed=0    unreachable=0    failed=0
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

[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

Red Hat Ansible Automation

Red Hat® Ansible® Automation consists of three products:

  • Red Hat® Ansible® Tower: Built for operationalizing and scaling automation, managing complex deployments and speeding up productivity. Extend the power of Ansible Tower with Workflows and Surveys to streamline jobs and simple tools to share solutions with your team.

  • Red Hat® Ansible® Engine: a fully supported product built on the foundational capabilities of the Ansible project. Also provides support for select modules including Infoblox.

  • Red Hat® Ansible® Network Automation: provides support for select networking modules from Arista (EOS), Cisco (IOS, IOS XR, NX-OS), Juniper (JunOS), Open vSwitch, and VyOS. Includes Ansible Tower, Ansible Engine, and curated content specifically for network use cases.

ansible_inventory_report's People

Contributors

benthomasson avatar cmccarthtest avatar gundalow avatar ipvsean avatar maccioni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible_inventory_report's Issues

AnsibleUndefinedVariable

Hello,
Im running the playbook and I get this error.

fatal: [r2 -> localhost]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'ansible_net_interfaces'"}

If I look in facts I have the attribute "ansible_net_interfaces"

thanks.

library declaration in ansible.cfg

The library is set to a path to napalm in the ansible.cfg, is this needed? I was able to run this successfully without napalm installed.

error when run inventory-ios.yml

TASK [gathering IOS XE facts] **************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: No JSON object could be decoded
fatal: [noc01as01]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File "/home/martin/.ansible/tmp/ansible-tmp-1540945702.87-111704655859437/AnsiballZ_ios_facts.py", line 113, in \n _ansiballz_main()\n File "/home/martin/.ansible/tmp/ansible-tmp-1540945702.87-111704655859437/AnsiballZ_ios_facts.py", line 105, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/martin/.ansible/tmp/ansible-tmp-1540945702.87-111704655859437/AnsiballZ_ios_facts.py", line 48, in invoke_module\n imp.load_module('main', mod, module, MOD_DESC)\n File "/tmp/ansible_ios_facts_payload_20JweU/main.py", line 543, in \n File "/tmp/ansible_ios_facts_payload_20JweU/main.py", line 529, in main\n File "/tmp/ansible_ios_facts_payload_20JweU/main.py", line 228, in populate\n File "/tmp/ansible_ios_facts_payload_20JweU/main.py", line 164, in populate\n File "/tmp/ansible_ios_facts_payload_20JweU/ansible_ios_facts_payload.zip/ansible/module_utils/network/ios/ios.py", line 135, in run_commands\n File "/tmp/ansible_ios_facts_payload_20JweU/ansible_ios_facts_payload.zip/ansible/module_utils/connection.py", line 167, in rpc\n File "/tmp/ansible_ios_facts_payload_20JweU/ansible_ios_facts_payload.zip/ansible/module_utils/connection.py", line 146, in _exec_jsonrpc\n File "/usr/lib/python2.7/json/init.py", line 339, in loads\n return _default_decoder.decode(s)\n File "/usr/lib/python2.7/json/decoder.py", line 364, in decode\n obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode\n raise ValueError("No JSON object could be decoded")\nValueError: No JSON object could be decoded\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.