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

Try it free for 30 minutesRun it on Lite from £3 a day

The free demo needs no card and no email. Every lab plan includes every guided lab.

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.

DevicePlatformManagement (Gi0/0 or Gi1)Links to configure
r1IOS 15.9 (IOSv), Netmiko cisco_ios10.10.20.11Gi0/1 10.1.12.1/30 → r2 · Gi0/2 10.1.13.1/30 → xe1 · Lo0 10.255.0.1/32
r2IOS 15.9 (IOSv), cisco_ios10.10.20.12Gi0/1 10.1.12.2/30 → r1 · Lo0 10.255.0.2/32
xe1IOS XE 17.3 (CSR 1000v), cisco_xe10.10.20.21Gi2 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

  1. Your first Netmiko session
  2. Finish the shared helper and gather facts
  3. Back up every configuration
  4. Turn data into configuration
  5. Push the configuration and save it
  6. Verify from the script
  7. 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.

Topology of Python and Netmiko - CLI automation over SSH4 nodes and 1 network, 6 links. Every link is listed as text below the diagram.devboxr1r2xe1Mgmteth0Gi0/1Gi0/1Gi0/2Gi2Gi0/0Gi1Gi0/0
4 nodes and 1 network, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in Python and Netmiko: CLI automation over SSH, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
devboxEVE-NG GUI server (Docker)eve-gui-server:latest1 vCPU, 1,024 MB
r1Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB
r2Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB
xe1Cisco CSR 1000vcsr1000vng-universalk9.17.03.08a-serial1 vCPU, 4,096 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Network Automation - CCNA and CCNP Automation guided labs.

  3. Open 06 - Python and Netmiko - CLI automation over SSH and 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

All 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.