Last Updated: May 1, 2025
Ansible for Networking
ansible-playbook -i inventory.yml playbook.ymlRun playbook against network inventory
ios_command moduleRun show commands on Cisco IOS devices
ios_config modulePush configuration to Cisco IOS devices
nxos_command / nxos_configCisco Nexus (NX-OS) equivalents
junos_command / junos_configJuniper JunOS equivalents
ansible_user / ansible_passwordCredentials (use vault for passwords!)
ansible_network_os: iosDefine device network OS type in inventory
connection: network_cliUse network CLI connection plugin (not SSH raw)
Netmiko (Python Library)
from netmiko import ConnectHandlerImport Netmiko for multi-vendor SSH
ConnectHandler(device_type='cisco_ios', host='...', username='...', password='...')Create SSH connection handler
net_connect.send_command('show version')Execute show command and return output
net_connect.send_config_set(commands)Push configuration set (list of commands)
net_connect.save_config()Save running to startup config
Supported platformscisco_ios, cisco_nxos, juniper, arista_eos, huawei, + many more
NAPALM (Multi-Vendor Abstraction)
from napalm import get_network_driverImport NAPALM driver framework
driver = get_network_driver('ios')Load driver for specific platform
device.open()Establish connection to the device
device.get_facts()Retrieve device facts (vendor-agnostic!)
device.get_interfaces()Get interface details (status, MAC, counters)
device.get_bgp_neighbors()Get BGP neighbor state (cross-platform)
device.load_merge_candidate(config)Stage configuration candidate
device.compare_config()Diff between running and candidate config
IaC for Networking
| Item | Description |
|---|---|
Configuration backup | Automatically backup configs daily (git-backed) |
Config templates | Jinja2 for generating device config from variables |
Validation/Testing | pyATS, Batfish — validate config before deployment |
GitOps for networks | PR-based config changes with CI pipeline validation |
Nornir | Python automation framework — faster than Ansible (no YAML overhead) |
Pro Tip: Start with read-only data gathering (facts, show commands) before writing config changes. Always backup running config before any automation change. Test in a lab first.