---
title: "Network Automation for CCNA: SDN and REST | CyberWithMadhav"
description: "Free CCNA lesson on automation: control and management planes, SDN, REST verbs, status codes, reading JSON, Ansible, Terraform and AI, with a JSON reader."
url: https://www.cyberwithmadhav.com/learn-ccna-network-automation.html
source_format: markdown rendering of the HTML page
---

[Learn](https://www.cyberwithmadhav.com/learn.html) / [Stage 3: Networking and CCNA](https://www.cyberwithmadhav.com/learn.html#stage-3) / Lesson 3.14

$ lesson 3.14 --track ccna --domain automation

# Network Automation and Programmability: Controllers, REST, JSON, Ansible and AI

The last CCNA topic is the one that changes how you will do all the others. Learn how controllers and APIs replace box by box configuration, read the JSON they return, see where Ansible, Terraform and AI fit, and how to stop automation from becoming the fastest way to break a network.

- Stage **3** Networking and CCNA
- Level **Advanced**
- **60** min
- **5** sections, quiz, lab

Start the lesson Jump to the lab

## In this lesson

1. Why automate, and the three planes
2. SDN: underlay, overlay, fabric and APIs
3. REST APIs
4. Reading JSON
5. Ansible, Terraform and AI
6. Flashcards
7. Quick quiz
8. Hands-on lab
9. Key takeaways

## By the end of this lesson you can

- Explain why automation helps and name the three planes
- Describe controller based networking and SDN layers and APIs
- Match CRUD to HTTP verbs and read common status codes and auth types
- Read and fix JSON and extract values by path
- Explain what Ansible, Terraform and AI do in network operations, and their risks

3.14.01

## Why automate, and the three planes

Typing the same NTP server into 300 devices by hand takes a day and produces a few typos. A script or tool does it in minutes, identically, and can report every device whose config has **drifted** from the standard. Automation does not replace network engineers; it removes repetitive work so they can design, review and troubleshoot.

Separating the planes is what makes controllers possible: the management and some control decisions can move off the box.

**Controller based networking** centralises management (and sometimes control) logic. Examples: Cisco Catalyst Center (formerly DNA Center) for campus, SD-WAN Manager for WAN, and APIC for ACI data centres. Instead of logging into each switch, you describe what you want once and the controller pushes it.

3.14.02

## SDN: underlay, overlay, fabric and APIs

Northbound is where your code talks to the controller. Southbound is how the controller talks to devices.

- **Underlay**: the physical IP network: links, routing, addresses.
- **Overlay**: virtual networks built as tunnels on top of the underlay, for example VXLAN.
- **Fabric**: underlay and overlay managed together as one system.

**Virtualisation** runs on the same idea of abstraction. A type 1 hypervisor runs on bare metal (VMware ESXi, Microsoft Hyper-V, KVM); a type 2 runs on top of an operating system (VirtualBox, VMware Workstation). Virtual machines each carry a full operating system; containers share the host's kernel and are lighter. In networking, a **VRF** gives one router several separate routing tables, so different customers or departments can even reuse the same addresses.

3.14.03

## REST APIs

REST is an architectural style, usually over HTTP: client and server, **stateless** (every request carries everything needed, including authentication), with resources identified by URLs.

| CRUD | HTTP verb | Example |
| --- | --- | --- |
| Create | POST | Add a device to the inventory |
| Read | GET | List devices |
| Update | PUT (replace) or PATCH (change part) | Change a device's location |
| Delete | DELETE | Remove a device |

| Code | Meaning |
| --- | --- |
| 200 OK | Success, here is the result |
| 201 Created | A new resource was made |
| 204 No Content | Success, nothing to return |
| 400 Bad Request | Your request is malformed |
| 401 Unauthorized | Not authenticated (missing or bad credentials or token) |
| 403 Forbidden | Authenticated, but not allowed |
| 404 Not Found | No such resource |
| 500 Internal Server Error | The server failed |

Authentication types: **HTTP Basic** (username and password Base64 encoded, which is encoding not encryption, so HTTPS only), **API keys**, **bearer tokens** (often obtained by first POSTing credentials, then sent in a header on each request), and **OAuth** for delegated access.

### A typical token flow

Use Next or the arrow keys. Paths are examples in the style of Cisco's APIC-EM API.

#### 1. Ask for a token

`POST /api/v1/ticket` with a JSON body containing username and password, over HTTPS.

#### 2. Receive it

The reply is `200` with JSON holding a ticket (token). A wrong password gets a `401` style error.

#### 3. Use it

`GET /api/v1/network-device` with the token in a header such as `X-Auth-Token`. No password travels again.

#### 4. Read the JSON

Parse the reply and pick out what you need, for example each device's hostname, as in the reader below.

3.14.04

## Reading JSON

**JSON** is the most common encoding for API data (XML and YAML are the others you will meet). Its types: an **object** `{ }` of key value pairs, an **array** `[ ]` of values, a **string** in double quotes, a **number**, `true` or `false`, and `null`. Keys must be strings in double quotes. Standard JSON allows no comments, no single quotes and no trailing commas.

### JSON reader: an inventory reply

Edit the JSON and check it, or load a broken example and find the mistake. Then type a path such as `response[0].hostname` to pull out one value.

JSON

Path

The JSON above is illustrative, written for this lesson. A real controller's field names may differ, so read what yours returns.

3.14.05

## Ansible, Terraform and AI

|  | Ansible | Terraform |
| --- | --- | --- |
| Style | Procedural tasks in order, aiming to be idempotent (safe to run twice) | Declarative: describe the end state |
| Language | YAML playbooks | HCL |
| How it reaches devices | Agentless, over SSH or APIs, using modules | Providers that talk to platform APIs |
| Dry run | `ansible-playbook --check` | `terraform plan`, then `apply` |
| Remembers | An inventory of hosts | A state file of what it created |

```
- name: Set NTP on all routers
  hosts: routers
  gather_facts: false
  tasks:
    - name: Push the NTP server
      cisco.ios.ios_config:
        lines:
          - ntp server 192.168.1.100
```

This uses the `ios_config` module from the `cisco.ios` collection; the inventory would put your routers in a `routers` group with `ansible_network_os: cisco.ios.ios` and `ansible_connection: network_cli`. Terraform has providers for Cisco platforms (for example IOS XE); the resource names depend on the provider version, so check its documentation before writing one.

**AI and machine learning** in network operations: predictive and ML tools learn a baseline of normal behaviour, flag anomalies and forecast capacity; generative AI drafts configs, summarises logs and answers questions in plain language. It can also be confidently wrong, so everything it produces is reviewed and lab tested like a junior engineer's change.
How attackers abuse this

A controller GUI or API token is a key to every device at once. Secrets also leak through code: passwords in playbooks, API keys committed to Git, and Terraform state files (which can hold sensitive values) left readable. And automation amplifies mistakes: one bad playbook can break every router in minutes.
Defender move

HTTPS only, short lived tokens, least privilege roles and MFA on controllers, API access only from admin networks; Ansible Vault or a secrets manager, never secrets in Git, encrypted and access controlled remote state; peer review, `--check` and `plan` before every change, staged rollouts, version control and a rollback plan.

## Flashcards: do you remember?

Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.

## Quick quiz

Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.

### Q1 Which HTTP verb reads data?

### Q2 A script gets 401 from the controller. Most likely:

### Q3 Which is valid JSON?

### Q4 Which interface does a controller use to configure devices?

### Q5 What makes Ansible different from many tools?

### Q6 Generative AI wrote a config for you. What next?

**0 / 6**

## Hands-on lab

Cisco Packet Tracer lab  50 minutes  simulated network

### Packet Tracer lab 3.14: talk to the Packet Tracer Network Controller with REST

**You need:** Cisco Packet Tracer (free with a Cisco Networking Academy account; version 9.0.1 was the current download on the NetAcad Resource Hub when this lesson was written). Packet Tracer 8.2 and later include a Network Controller device that, per Cisco's PT FAQ, offers a web GUI and APIs reachable from a browser, Python or Postman. That FAQ page could not be opened directly when this was written (it was read from a search result), so treat the details as UNVERIFIED. Devices: Network Controller, 2 x ISR4331, 1 x 2960, 1 x PC-PT.

**Simulator lab, zero risk.** This lab runs inside Cisco Packet Tracer, so it touches no real network. Packet Tracer is free with a Cisco Networking Academy account (netacad.com). It simulates a subset of Cisco IOS, so where support for a feature is uncertain we say so instead of promising it works.

#### Topology and addressing

Controller, Admin-PC and R1 Gi0/0/0 on SW1. R1 Gi0/0/1 to R2 Gi0/0/1 (10.0.12.0/30).

| Device | Interface | IPv4 address / prefix | Default gateway or note |
| --- | --- | --- | --- |
| Controller | Gi0 | 192.168.1.200/24 | gateway 192.168.1.1 |
| R1 | Gi0/0/0 / Gi0/0/1 | 192.168.1.1/24 / 10.0.12.1/30 |  |
| R2 | Gi0/0/1 | 10.0.12.2/30 | static route to 192.168.1.0/24 via 10.0.12.1 |
| SW1 | VLAN 1 | 192.168.1.2/24 | gateway .1 |
| Admin-PC | Fa0 | 192.168.1.50/24 | gateway .1 |

1. Prepare the devices`R1(config)#  hostname R1   R1(config)#  ip domain-name cwm.lab   R1(config)#  username admin secret <a long password>   R1(config)#  crypto key generate rsa modulus 2048   R1(config)#  line vty 0 4   R1(config-line)#  login local   R1(config-line)#  transport input ssh   R2(config)#  ip route 192.168.1.0 255.255.255.0 10.0.12.1`Repeat the SSH setup on R2 and SW1.  Done
2. Controller GUIFrom Admin-PC's browser open http://192.168.1.200 (or https, depending on the build), create the admin account, and add R1, R2 and SW1 with their SSH credentials. The section is called something like Provisioning or Discovery; names vary by build and are UNVERIFIED.  Done
3. Compare viewsRead the controller's inventory and topology views and compare them with `show cdp neighbors` on R1.  Done
4. REST from Admin-PCOpen Desktop, Programming (Packet Tracer's Python environment). The controller is commonly documented with APIC-EM style endpoints: `POST /api/v1/ticket` to get a token and `GET /api/v1/network-device` with an `X-Auth-Token` header. These paths, the header name and the Python modules available inside Packet Tracer are UNVERIFIED for your build: open the controller's own API documentation page and Packet Tracer's sample programs first, then write the script.  Done
5. Read the replyIn the JSON you get back, find an object, an array, a string and a number, and write down the path to each device's hostname, as in the JSON reader in this lesson.  Done
6. Paper exerciseOutside Packet Tracer: write a short Ansible playbook outline that sets the NTP server on all routers (like the one above), then describe the same intent as a Terraform outline. What would `--check` and `terraform plan` show you before anything changes?  Done

**You are done when:** The controller lists R1, R2 and SW1 as managed and reachable; your script prints a successful (200) reply for the token request and for the device list, and a wrong password gives an authentication error (a 401 style code; the exact code in Packet Tracer is UNVERIFIED).

#### Packet Tracer limits and notes

- Ansible, Terraform, NETCONF and RESTCONF do not run inside Packet Tracer. Practise them later on a Linux machine (Stage 2 of this path prepares you).
- Packet Tracer's Programming environment supports a subset of Python with its own HTTP helper modules; exact module names are UNVERIFIED, so start from its sample programs.
- Field names in a real controller reply may differ from the illustration in this lesson. The AI and machine learning topic has no Packet Tracer lab: as a discussion exercise, take a syslog excerpt and an AI generated root cause, and check whether the logs really support it.
- Packet Tracer simulates a subset of IOS. If a command here is rejected in your version, note it, skip that step and carry on; the concept still applies to real Cisco gear.

[Download the lab checklist (.txt)](https://www.cyberwithmadhav.com/assets/learn/learn-ccna-network-automation-lab-checklist.txt)  Print it or keep it open beside Packet Tracer.

## Key takeaways

- Automation brings speed, consistency and drift detection; engineers still design and review.
- Data, control and management planes; controllers centralise the management side.
- Northbound to the controller, southbound to devices.
- REST: POST, GET, PUT or PATCH, DELETE, and know 200, 201, 204, 400, 401, 403, 404, 500.
- JSON: double quotes, no comments, no trailing commas.
- Protect tokens and secrets, dry run every change, and verify anything AI writes.

Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.

[Previous 3.13 Wireless LANs: RF Basics, WLC and Lightweight APs, WPA2 and WPA3](https://www.cyberwithmadhav.com/learn-ccna-wireless-lans.html)[Next Stage 4: Security Fundamentals (coming soon)](https://www.cyberwithmadhav.com/learn.html#stage-4)
