Network Automation: Ansible and Python
Network automation is essential in 2026 for efficiently managing 50+ devices. Ansible, Python (NAPALM, Netmiko, PyEZ), Terraform, and NETCONF/YANG are the established standards. This guide covers the fundamentals: tools, best practices, real-world examples, network CI/CD, and GitOps.
Why Automate
- Reduce human error (CLI typos)
- Ensure configuration consistency (no drift between switches)
- Accelerate deployment (push 100 VLANs in 5 min vs. 4 hours)
- Maintain traceability (Git history)
- Enable fast rollback
- Maintain living documentation (configuration = code)
Core Tools
Ansible
- Agentless (SSH/NETCONF/HTTPS)
- Vendor-specific modules: cisco.ios, cisco.nxos, arista.eos, juniper.junos, fortinet.fortios
- Simple YAML syntax and a large community
- Idempotent: running it multiple times produces the same result
- Inventory: static or dynamic (Nautobot, NetBox)
Python + Libraries
- Netmiko: basic multi-vendor SSH connectivity
- NAPALM: unified API (get_facts, get_interfaces, config merge)
- PyEZ (Juniper): native NETCONF/YANG support
- Nornir: Python orchestration framework
- Requests: REST API
Terraform
- Declarative infrastructure as code
- Providers: VMware NSX, AWS, Azure, Cisco ACI, FortiGate, Palo Alto Panorama
- State file: reflects the deployed state
- Ideal for cloud infrastructure + devices with REST APIs
NETCONF/YANG
- IETF standard (RFC 6241)
- Configuration/data modeling with YAML + XML
- Supported platforms: Cisco IOS-XE/NX-OS, Juniper Junos, Arista EOS
- Preferred over CLI parsing for reliability
Source of Truth (SoT)
All automation starts with a SoT:
- Nautobot / NetBox (open source): IPAM + DCIM + automation
- Infoblox DDI: commercial, enterprise market leader
- Excel (for getting started) — not scalable
- YAML files in Git (simple, GitOps-friendly)
- DNAC inventory (Cisco)
Ansible Example: Push a VLAN to 10 Cisco Switches
- # inventory.yml: all switches tagged with the 'access' group
- # playbook-vlans.yml
- - hosts: access
- tasks:
- - name: Create VLAN 10
- cisco.ios.ios_vlan:
- vlan_id: 10
- name: DATA
- state: present
Python NAPALM Example (Get Facts)
- from napalm import get_network_driver
- driver = get_network_driver('ios')
- dev = driver('10.0.0.1', 'admin', 'pass')
- dev.open()
- print(dev.get_facts())
- print(dev.get_interfaces_ip())
- dev.close()
Network CI/CD (GitOps)
Typical Workflow
- 1. An engineer modifies YAML in a Git repository
- 2. Pull Request + peer review
- 3. CI pipeline: syntax validation, Ansible/Batfish dry run
- 4. Merge → automatic deployment (or manual approval)
- 5. Post-deployment testing (ping, BGP state)
- 6. Automatic rollback if a test fails
CI/CD Tools
- GitLab CI, GitHub Actions, Jenkins
- Batfish: configuration validation before deployment (dry run)
- SuzieQ: network observability for CI testing
- pytest + Nornir: programmable testing
Vendor Orchestration Platforms
- Cisco DNA Center: SD-Access orchestration and Assurance
- Juniper Apstra: intent-based, multi-vendor platform (see article)
- FortiManager: template and policy orchestration
- Aruba Central (SaaS): cloud-based provisioning
- NetBrain: automation + network assessment
AIOps (Emerging)
- Juniper Mist Marvis: AI chatbot for troubleshooting
- Cisco ThousandEyes AI: anomaly detection
- HPE AIOps: ML models for predicting saturation
Maturity Model
- Level 1: manual ad hoc scripts (one-off Python scripts)
- Level 2: Ansible playbooks + static SoT (YAML/Excel)
- Level 3: CI/CD + dynamic SoT (Nautobot/NetBox)
- Level 4: intent-based automation (Apstra, DNA Center)
- Level 5: self-healing + AI (Marvis, DNA Center AI)
Order from OPTINOC
Network automation training (Ansible + Python + NetBox/Nautobot) for customer teams. Network CI/CD deployment. Juniper Apstra / Cisco DNA Center integration. Quote within 48 hours.
