tech/cisco/automation

AUTOMATION

Cisco network automation — Netmiko/NAPALM Python, Ansible, DNA Center REST API, NSO, YANG/NETCONF/RESTCONF.

production
requires: tech/cisco
improves: tech/cisco

Cisco Network Automation

Stub — full skill pending. Core patterns documented below.

Toolchain

ToolAbstraction levelBest for
NetmikoSSH screen-scrapingQuick config push/pull, legacy IOS
NAPALMMulti-vendor abstractionGetter-based read (facts, interfaces, routes)
Ansible (cisco.ios collection)Playbook/idempotentConfig management, compliance checks
DNA Center REST APIIntent-basedInventory, templates, assurance on Catalyst 9K
NSOService abstractionMulti-vendor service orchestration at scale
NETCONF/RESTCONFYANG modelStructured config on IOS-XE 16.6+, NX-OS 9.3+

Netmiko (Python)

from netmiko import ConnectHandler

device = {
    "device_type": "cisco_ios",
    "host": "192.168.1.1",
    "username": "admin",
    "password": "secret",
}

with ConnectHandler(**device) as net_connect:
    output = net_connect.send_command("show ip interface brief")
    print(output)

    # Push config
    config_commands = [
        "interface GigabitEthernet0/1",
        "description UPLINK",
        "no shutdown",
    ]
    net_connect.send_config_set(config_commands)

NAPALM getters

from napalm import get_network_driver

driver = get_network_driver("ios")
device = driver("192.168.1.1", "admin", "secret")
device.open()

facts = device.get_facts()           # hostname, model, serial, uptime
interfaces = device.get_interfaces() # speed, mtu, description
routes = device.get_route_to("0.0.0.0/0")

device.close()

Ansible (cisco.ios collection)

# inventory.yml
all:
  hosts:
    sw01:
      ansible_host: 192.168.1.1
      ansible_network_os: cisco.ios.ios
      ansible_user: admin
      ansible_password: "{{ vault_password }}"
      ansible_connection: network_cli

# playbook — gather facts
- name: Collect IOS facts
  hosts: all
  gather_facts: false
  tasks:
    - name: Get facts
      cisco.ios.ios_facts:
        gather_subset: all

    - name: Set interface description
      cisco.ios.ios_interfaces:
        config:
          - name: GigabitEthernet0/1
            description: "UPLINK-TO-CORE"
        state: merged

DNA Center — device inventory via REST

import requests

# Authenticate
auth = requests.post(
    "https://dnac.example.com/dna/system/api/v1/auth/token",
    auth=("admin", "password"),
    verify=False
)
token = auth.json()["Token"]

# List devices
devices = requests.get(
    "https://dnac.example.com/dna/intent/api/v1/network-device",
    headers={"X-Auth-Token": token},
    verify=False
)
for d in devices.json()["response"]:
    print(d["hostname"], d["managementIpAddress"], d["softwareVersion"])

Gotchas