Innsikt fra Bluetree | Hold deg oppdatert innen IT og teknologi.

[My Journey to CCIE Automation – Week 4] Automating Network Discovery and Reports with Python & Ansible

Written by Bjørnar Lintvedt | 5 September, 2025
My journey continues

👋 Hi, I’m Bjørnar Lintvedt

I’m a Senior Network Consultant at Bluetree, working at the intersection of networking and software development.

As mentioned in my first blog post, I’m preparing for the CCIE Automation lab exam — Cisco’s most advanced certification for network automation and programmability. I’m documenting the journey here with weekly, hands-on blog posts tied to the blueprint.

Link to my GitLab Repo

 

Week 4

After NETCONF in Week 3, I wanted to pick something network engineers often do manually — discovering devices, collecting facts, and documenting neighbors — and automate it with Python and Ansible.

This week’s project: Network discovery and reports. A small workflow that scans a subnet, discovers devices, runs commands, and generates a nice HTML report.

 

What I built

1. Python Discovery script

A Python CLICK app (network_discovery.py) that:

  • Scans a subnet for devices with SSH open.
  • Logs in with username/password using Netmiko.
  • Detects whether the device runs IOS or NX-OS.
  • Builds an Ansible inventory file with the correct ansible_network_os.
  • Executes an Ansible playbook that will
    • gather facts about the discovered hosts: 
      • Hostname
      • Hardware model
      • Software version
      • CDP/LLDP neighbors
    • Then generate a HTML report listing the discovered hosts and the facts gathered

Sample from script (see repo for full details):

 

2. Ansible Playbook

The playbook (gather_device_facts.yml) runs against the discovered hosts and gathers system + neighbor info and generates a HTML report.

 

Sample of gathering data from the discovered hosts:

Right now it only supports Cisco IOS and Nexus, but it can easily be extended to other platforms.

 

3. HTML Report

Instead of raw CLI output, I render a single HTML report with a Jinja2 template. Every device is listed in a table, with expandable CDP/LLDP sections.

Sample from jinja2 template:

4. The result => View the HTML report

You get a list of all hosts discovered with a column for

  • IP
  • Hostname
  • Model
  • Version
  • OS

At the end you get a list of all CDP and/or LLDP neighbors for each device discovered.

 
How to run

See README in Gitlab repository :)

 

Service Interactions update

I've updated the new use case to the Nautix diagram

 


 

📅 What’s Next
In Week 5 I will focus on working with pyATS:
  Blueprint item 3.3 Modify and troubleshoot an automated test by using pyATS to meet requirements
3.3.a Create a testbed file for connecting to Cisco IOS,  IOS XE, or NX-OS devices
3.3.b Gather current configuration and operational state from devices using the Genie parsers and models included with pyATS

3.3.c Develop and execute test jobs and scripts using AEtest to verify network health

 

🔗 Useful Links

 

Blog series