• Stars
    star
    130
  • Rank 276,039 (Top 6 %)
  • Language
    HTML
  • License
    Other
  • Created almost 7 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

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.

More Repositories

1

toolkit

Ansible Content Collection for common network functions like dynamic documentation
Jinja
109
star
2

ansible-napalm-samples

GitHub Repo comparing NAPALM and Ansible on Cisco NXOSv and Arista vEOS
Python
102
star
3

networking-icons

Repo containing various networking icons including routers, switches, servers, firewalls, load balancers and more. Icons are provided in png and svg formats.
67
star
4

ansible-network-parsers

Collection of Network CLI parsers using Ansible parse_cli filter.
34
star
5

agnostic_example

cli_command and cli_config agnostic network automation modules for the network_cli connection plugin
33
star
6

infoblox_ansible

examples of Ansible with Infoblox NIOS
31
star
7

ipaddr_filter

examples with the ipaddr filter
24
star
8

diff_configs

Examples of several diffs on nxos using the nxos_config Ansible module
21
star
9

net_check

demonstration of checking the operational status of a network using declarative intent parameters and the net_ping module
HTML
12
star
10

httpapi

example using the httpapi connection plugin
11
star
11

an-demos

Ansible Networking Demos
Ruby
8
star
12

aggregate_resources

This repo contains an example of the aggregate parameter compared to using a traditional loop. This demonstration is done on Arista vEOS using the eos_vlan module.
8
star
13

dynamic-infoblox

A collection of Ansible Roles to automate Infoblox Core Network Services
Shell
7
star
14

operating_state

An Ansible role to collect operating state information from network devices.
Python
5
star
15

cisco_ios_command_parsers

Command parsers for Ansible network-engine
4
star
16

ansible-jupyter-notebooks

Notebooks
4
star
17

panos-instruqt

Playbooks and roles for PAN-OS instruqt lab
HTML
4
star
18

ansible-bgpaas

BGPaaS: BGP Route-Reflectors As A Service
3
star
19

change_password

simple example to change the password on a network platform
2
star
20

network_vars

example network variables to use with network.toolkit
1
star
21

netconf

1
star
22

bigswitch

BigSwitch Fabric Platform role
1
star
23

F5_Big-IP_LTM_examples

F5 Big-IP load balancing examples
1
star
24

vlans

Ansible Collection illustrating _vlans resource modules
1
star
25

debugging-variables

Sometimes it's useful to debug where and how your playbook variables are defined.
1
star
26

ebook

1
star
27

cli_parse_templates

cli parse templates
1
star