Network Automation Cheat Sheet

Network automation essentials: Ansible for network devices, Netmiko for SSH-based automation, NAPALM for multi-vendor abstraction, and Infrastructure as Code for .

Last Updated: May 1, 2025

Ansible for Networking

ansible-playbook -i inventory.yml playbook.yml
Run playbook against network inventory
ios_command module
Run show commands on Cisco IOS devices
ios_config module
Push configuration to Cisco IOS devices
nxos_command / nxos_config
Cisco Nexus (NX-OS) equivalents
junos_command / junos_config
Juniper JunOS equivalents
ansible_user / ansible_password
Credentials (use vault for passwords!)
ansible_network_os: ios
Define device network OS type in inventory
connection: network_cli
Use network CLI connection plugin (not SSH raw)

Netmiko (Python Library)

from netmiko import ConnectHandler
Import 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 platforms
cisco_ios, cisco_nxos, juniper, arista_eos, huawei, + many more

NAPALM (Multi-Vendor Abstraction)

from napalm import get_network_driver
Import 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

ItemDescription
Configuration backupAutomatically backup configs daily (git-backed)
Config templatesJinja2 for generating device config from variables
Validation/TestingpyATS, Batfish — validate config before deployment
GitOps for networksPR-based config changes with CI pipeline validation
NornirPython 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.