HOWTO: Export NetBox Inventory for Ansible and Nornir¶
Purpose: Run the NetBox inventory exporter, validate both Ansible and Nornir output, and configure the CI/CD freshness check.
Difficulty: Intermediate
Track: IPAM-Driven Infrastructure
Overview¶
Inventory export is not a one-time task: it is a regular pipeline step that keeps Ansible and Nornir synchronised with NetBox. This HOWTO covers the export command, output validation, and the CI/CD integration that prevents automation runs on stale inventory data.
1. Running the Exporter¶
make inventory.netbox-exportcommand.- Exporter configuration: NetBox URL, token, filter parameters.
- Output file locations:
netbox_hosts.yamlandnetbox_inventory.yaml.
2. Validating Ansible Inventory Output¶
- Schema structure:
all.hosts, group memberships, host variables. - Required variables:
ansible_host,env,role,site. - Confirming expected device count.
3. Validating Nornir Inventory Output¶
- Schema structure: host entries with
hostname,platform,groups,data. - Group resolution:
env_*androle_*groups present. - Spot-checking a specific host entry.
4. Testing Device Reachability¶
- Running an Ansible ping against a subset of hosts.
- Running a Nornir connectivity test.
- Diagnosing unreachable hosts: IP mismatch, firewall, DNS.
5. CI/CD Freshness Check¶
- Freshness check configuration: max age in hours.
- Pipeline step:
make inventory.check-freshness. - Handling a freshness failure in the pipeline.
References¶
- ADR-0002 – Source of Truth: NetBox-Driven Inventory
- HOWTO: Use NetBox as Source of Truth for Ansible and Nornir
- HOWTO: Allocate IPs from NetBox
License: MIT-0 for code, CC-BY-4.0 for documentation unless otherwise stated.