Network automation lab 6 of 27
Python and Netmiko: CLI automation over SSH
Automate three routers over SSH with Python and Netmiko: gather facts, back up configurations, push interface settings from a YAML file, verify with pings, and run against every device in parallel while handling the ones that fail.
Run this lab
It needs Lite: its 4 nodes are set to 4 vCPU and 6,144 MB in total. That fits the free demo too.
In your workspace: Shared, then Network Automation - CCNA and CCNP Automation guided labs, then 06 - Python and Netmiko - CLI automation over SSH
- Level
- Intermediate
- Time
- About 80 minutes
- Nodes need
- 4 vCPU, 6,144 MB
- Smallest plan
- Lite
The scenario
Kestrel Freight's three branch routers still have unaddressed links: r1 connects to r2 and to the IOS XE router xe1, but nobody has configured the interfaces. The team wants it done by script, not by hand, so that the same code can later configure fifty branches. You'll build a small Netmiko toolkit: gather facts, back up configurations, push interface settings from intended.yaml, prove the links work, and run everything in parallel without one dead router stopping the rest.
| Device | Platform | Management (Gi0/0 or Gi1) | Links to configure |
|---|---|---|---|
| r1 | IOS 15.9 (IOSv), Netmiko cisco_ios | 10.10.20.11 | Gi0/1 10.1.12.1/30 → r2 · Gi0/2 10.1.13.1/30 → xe1 · Lo0 10.255.0.1/32 |
| r2 | IOS 15.9 (IOSv), cisco_ios | 10.10.20.12 | Gi0/1 10.1.12.2/30 → r1 · Lo0 10.255.0.2/32 |
| xe1 | IOS XE 17.3 (CSR 1000v), cisco_xe | 10.10.20.21 | Gi2 10.1.13.2/30 → r1 · Lo0 10.255.0.3/32 |
Files in ~/lab: inventory.yaml (the routers), intended.yaml (the interface settings), netlab.py (shared helpers with one TODO). Device login netops / NetOps-Lab1, available to your scripts as $NET_USER and $NET_PASS.
What you’ll practise
- Open SSH sessions to IOS and IOS XE with Netmiko and run show commands
- Keep credentials out of code and devices in an inventory file
- Generate configuration commands from structured data and push them with send_config_set
- Verify a change from the script itself (pings, interface state) and save the configuration
- Handle unreachable devices and authentication failures, and speed up runs with threads
The tasks
- Your first Netmiko session
- Finish the shared helper and gather facts
- Back up every configuration
- Turn data into configuration
- Push the configuration and save it
- Verify from the script
- Survive failures and go parallel
The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.
Topology and devices
The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.
Every link, as text
- devbox
eth0to Mgmt (network) - r1
Gi0/0to Mgmt (network) - r2
Gi0/0to Mgmt (network) - xe1
Gi1to Mgmt (network) - r1
Gi0/1to r2Gi0/1 - r1
Gi0/2to xe1Gi2
| Node | Device | Image in Add Node | Set to |
|---|---|---|---|
| devbox | EVE-NG GUI server (Docker) | eve-gui-server:latest | 1 vCPU, 1,024 MB |
| r1 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
| r2 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
| xe1 | Cisco CSR 1000v | csr1000vng-universalk9.17.03.08a-serial | 1 vCPU, 4,096 MB |
How to open this lab
Sign in to your workspace at
lab.cloudlabbox.com.In File Manager, open Shared, then the folder
Network Automation - CCNA and CCNP Automation guided labs.Open
06 - Python and Netmiko - CLI automation over SSHand start its nodes, then open Lab Tasks for the scenario and the steps.
The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.
More Network automation labs
Related labs in other courses
CloudLabBox is independent of Cisco. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.