Cisco Network Automation

AUTOMATION

Automating Cisco networks — NETCONF/YANG, REST APIs (DNA Center, Meraki), Ansible for IOS configuration, and Terraform for infrastructure provisioning.

ciscoautomationnetconfyangrest-apiansibleterraformprogrammability

Overview

A human network engineer can configure a router in a few minutes. In an enterprise with a thousand routers, that means thousands of minutes — each with its own potential for typos, missed steps, and configuration drift. When you need to push the same SNMP server address to every device, or change a NTP configuration fleet-wide, the only scalable approach is automation.

Network automation is not new — network teams have been writing expect scripts and TFTP-based config pushes for decades. What has changed is the tooling. Modern automation tools are structured, declarative, version-controlled, and testable. They treat network configuration the way software engineers treat code: as something that can be reviewed, tested, rolled back, and reproduced exactly.


The Three Network Planes

Before diving into automation tools, it helps to be clear about which part of the network they affect:

PlaneWhat It DoesExamples
Data planeForwards packets based on tablesSwitch ASICs forwarding frames, router FIB lookups, ACL enforcement
Control planeBuilds and maintains forwarding tablesOSPF computing routes, STP selecting the root bridge, ARP populating MAC tables
Management planeConfigures and monitors the deviceSSH CLI sessions, SNMP GET/SET, NETCONF, syslog output

Automation tools primarily operate on the management plane — they interact with device management interfaces to read and write configuration and operational state. Software-Defined Networking (SDN) goes further by centralising the control plane on a controller (as DNS Center does for SD-Access), removing per-device routing decisions.

Traditional network management relies on human operators individually logging into devices via SSH and typing commands. This approach does not scale, produces configuration drift (devices accumulate individual changes over time and deviate from the intended baseline), and makes it difficult to prove what changed, when, and why.


NETCONF

NETCONF (Network Configuration Protocol) is defined in RFC 6241. It provides a structured, reliable mechanism for reading and writing device configuration — the opposite of screen-scraping CLI output.

Key NETCONF characteristics:

Core NETCONF Operations

OperationPurpose
get-configRetrieve the current configuration (running, startup, or candidate datastore)
edit-configModify the configuration in the candidate datastore
commitApply the candidate configuration to the running configuration
getRetrieve operational state data (not just configuration — also ARP tables, interface counters)
lock / unlockLock the datastore to prevent concurrent conflicting changes
validateValidate a proposed configuration against the device’s schema without committing

The advantage of edit-config + commit over CLI is that a partial failure does not leave the device in an inconsistent state. Either the entire change commits or none of it does.

A NETCONF session interaction looks like this:

<!-- Client sends: get the running configuration -->
<rpc message-id="101">
  <get-config>
    <source><running/></source>
    <filter type="subtree">
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
    </filter>
  </get-config>
</rpc>

The device returns XML-structured configuration data that can be parsed reliably by any programming language — no regex parsing of human-readable CLI output required.


YANG Data Models

YANG (Yet Another Next Generation) is a data modelling language defined in RFC 6020. If NETCONF is the protocol for exchanging data, YANG defines the schema — the exact structure, data types, and valid values for every piece of configuration and operational data on a device.

A YANG model defines the tree structure of configuration:

container interfaces {
  list interface {
    key "name";
    leaf name {
      type string;
      description "Interface name, e.g. GigabitEthernet0/0";
    }
    leaf description {
      type string;
    }
    container ipv4 {
      leaf address { type inet:ipv4-address; }
      leaf mask { type string; }
    }
    leaf enabled { type boolean; default true; }
  }
}

YANG models come from two sources:

YANG models are the foundation for all structured management of modern network devices. Even when using higher-level tools like Ansible or DNA Center, YANG models define what the underlying data looks like.


REST APIs

REST (Representational State Transfer) is an architectural style for APIs that uses standard HTTP methods over HTTPS. Most modern network management platforms expose REST APIs for programmatic control.

HTTP Methods in Network Automation

MethodCRUDTypical Use
GETReadRetrieve device inventory, retrieve interface configuration, fetch event logs
POSTCreateCreate a new object, trigger an action (deploy, restart)
PUTReplaceReplace an entire resource with a new version
PATCHUpdateModify specific fields of an existing resource
DELETEDeleteRemove a resource

REST APIs are stateless — each request must include all authentication and context information. Responses are typically JSON-formatted.

HTTP Status Codes

CodeMeaningTypical Cause
200OKSuccessful GET or PUT
201CreatedSuccessful POST that created a new resource
204No ContentSuccessful DELETE (no body in response)
400Bad RequestMalformed request body or invalid parameters
401UnauthorizedMissing or invalid authentication credentials
403ForbiddenAuthenticated but not authorised for this resource
404Not FoundRequested resource does not exist
500Internal Server ErrorServer-side error — check platform logs

DNA Center REST API

DNA Center exposes a comprehensive REST API under the intent API path. Every GUI action in DNA Center can also be performed via API:

# Authenticate and get token
POST https://dnac/dna/system/api/v1/auth/token
Authorization: Basic <base64-encoded credentials>
→ Returns: {"Token": "eyJhbGciO..."}

# List all network devices
GET https://dnac/dna/intent/api/v1/network-device
X-Auth-Token: <token>
Content-Type: application/json
→ Returns JSON array of all managed devices with ID, hostname, IP, platform, software version

DNA Center API uses token-based authentication. The token is obtained with a POST to the auth endpoint using Basic auth, then included in subsequent requests as a header. Tokens expire after a defined period.

Meraki Dashboard API

Cisco Meraki (the cloud-managed networking platform) exposes a REST API via the Meraki Dashboard. Authentication uses a static API key per organisation. The Meraki API is particularly clean and well-documented, making it a common starting point for network automation beginners:

GET https://api.meraki.com/api/v1/organizations/{orgId}/devices
X-Cisco-Meraki-API-Key: <api-key>
→ Returns list of all devices in the organisation

Cisco DevNet provides a free sandbox environment (developer.cisco.com/site/sandbox/) with always-on DNA Center, Meraki, and IOS XE instances for practising API automation without requiring physical hardware.


Ansible for Cisco Networks

Ansible is an agentless automation framework that uses YAML-based playbooks to define desired configuration state. For network devices, Ansible connects via SSH (for CLI-based modules) or via API (for modules that use REST/NETCONF directly).

Key Ansible Concepts

ConceptDescription
InventoryA file (static or dynamic) listing managed hosts, grouped by role (routers, switches, firewalls)
PlaybookYAML file defining a list of plays; each play targets a host group and contains tasks
TaskA single operation executed by a module
ModuleReusable unit of work; Cisco IOS modules are in the cisco.ios collection
RoleReusable bundle of tasks, variables, and handlers for a specific function
IdempotentRunning the same playbook multiple times produces the same result — no duplicate changes

Cisco IOS Collection Modules

The cisco.ios Ansible collection provides modules purpose-built for IOS and IOS XE devices:

ModulePurpose
cisco.ios.ios_configPush arbitrary IOS configuration lines
cisco.ios.ios_commandRun show commands and capture output
cisco.ios.ios_factsGather facts (hostname, interfaces, routing, etc.) from the device
cisco.ios.ios_interfacesManage interface configuration in a structured way
cisco.ios.ios_vlansManage VLANs on IOS switches
cisco.ios.ios_ntp_globalManage NTP server configuration
cisco.ios.ios_bgp_globalManage BGP global configuration

Example Playbook

---
- name: Configure NTP and hostname on all routers
  hosts: cisco_routers
  gather_facts: no
  connection: network_cli

  tasks:
    - name: Set NTP server
      cisco.ios.ios_ntp_global:
        config:
          servers:
            - server: 192.168.1.1
              prefer: true
        state: merged

    - name: Configure interface description
      cisco.ios.ios_interfaces:
        config:
          - name: GigabitEthernet0/0
            description: "WAN uplink to ISP"
            enabled: true
        state: merged

The state: merged directive is key to idempotency — it applies only the changes needed to bring the device to the desired state, without removing existing configuration that is not in the playbook.

Inventory File Example

[cisco_routers]
router1 ansible_host=10.0.0.1
router2 ansible_host=10.0.0.2

[cisco_switches]
switch1 ansible_host=10.0.1.1
switch2 ansible_host=10.0.1.2

[all:vars]
ansible_user=admin
ansible_ssh_pass={{ vault_password }}
ansible_network_os=cisco.ios.ios

Secrets like passwords should be stored in Ansible Vault (encrypted) rather than in plaintext inventory files.


Terraform for Cisco

Terraform by HashiCorp takes a different approach from Ansible. Where Ansible focuses on configuration management (what settings are on existing devices), Terraform focuses on infrastructure provisioning — creating, modifying, and destroying infrastructure resources.

Terraform uses HCL (HashiCorp Configuration Language), a declarative language that defines the desired end state:

terraform {
  required_providers {
    aci = {
      source  = "CiscoDevNet/aci"
      version = "~> 2.0"
    }
  }
}

provider "aci" {
  username = "admin"
  password = var.aci_password
  url      = "https://aci-apic.example.com"
  insecure = false
}

resource "aci_tenant" "engineering" {
  name        = "Engineering"
  description = "Engineering department tenant"
}

resource "aci_vrf" "engineering_vrf" {
  tenant_dn = aci_tenant.engineering.id
  name      = "Engineering_VRF"
}

Terraform Workflow

  1. terraform init — download required providers and initialise working directory
  2. terraform plan — dry run; shows what changes will be made without making them
  3. terraform apply — make the changes; create/modify/destroy resources to match the declared state
  4. terraform destroy — remove all resources managed by this configuration

Terraform maintains a state file (terraform.tfstate) that tracks the current real-world state of all managed resources. This allows Terraform to determine the delta between the desired state and the current state on each run.

Cisco providers available for Terraform:


Python with Netmiko and NAPALM

Before Ansible and Terraform became standard, the dominant approach to network automation was Python with SSH libraries. These tools remain widely used and are important for custom scripts and integrations.

Netmiko is a Python library that simplifies SSH connections to multi-vendor network devices. It handles the connection, prompt detection, and command output parsing:

from netmiko import ConnectHandler

device = {
    "device_type": "cisco_ios",
    "host": "10.0.0.1",
    "username": "admin",
    "password": "cisco123",
}

with ConnectHandler(**device) as conn:
    output = conn.send_command("show ip route")
    conn.send_config_set(["ntp server 192.168.1.1"])
    print(output)

NAPALM (Network Automation and Programmability Abstraction Layer with Multivendor support) provides a higher-level abstraction. The same Python code works against Cisco IOS, Juniper JunOS, and Arista EOS by using a unified API:

from napalm import get_network_driver

driver = get_network_driver("ios")
device = driver("10.0.0.1", "admin", "password")
device.open()
facts = device.get_facts()
interfaces = device.get_interfaces()
device.close()

NAPALM is particularly useful for gathering consistent operational data (interface status, ARP tables, BGP peers) across a multi-vendor environment.


Infrastructure as Code Benefits

Treating network configuration as code — stored in Git, reviewed via pull requests, and deployed by pipelines — brings software engineering discipline to network operations:

BenefitExplanation
Version historyEvery change is recorded in Git with author, timestamp, and commit message
Peer reviewChanges are reviewed before they are applied — the same as a code review
RepeatabilityThe same code produces the same infrastructure every time; no manual steps
RollbackRevert a bad commit and re-apply the previous configuration
Drift detectionRun Ansible or Terraform in check mode to identify devices that have drifted from the defined baseline
CI/CD pipelinesAutomated testing (syntax check, lint, dry-run) before changes are applied to production

Cisco DevNet Resources

Cisco’s DevNet program provides certification tracks and learning resources specifically for network programmability:

CertificationFocus
Cisco Certified DevNet AssociateREST APIs, Python scripting, NETCONF/YANG, Ansible basics, DNA Center API, Meraki API
Cisco Certified DevNet ProfessionalAdvanced automation, application development on Cisco platforms, CI/CD for networks, Terraform, advanced YANG modelling

The DevNet Sandbox (developer.cisco.com/site/sandbox/) provides free, always-on and reservation-based lab access to DNA Center, Meraki, ACI, IOS XE, and other platforms — all via real APIs, with no physical hardware required. It is the fastest way to start practising network automation without building a home lab.