Network automation lab 12 of 27
Ansible for IOS and IOS XE: inventory, ad-hoc commands, facts and ios_config
Build an Ansible project for three routers from scratch: an inventory with groups and variables, ad-hoc commands, a facts playbook that writes JSON reports, and a configuration playbook with check mode, diffs, backups, saving and verification that is idempotent on the second run.
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 12 - Ansible for IOS and IOS XE - inventory ad-hoc commands facts and ios_config
- Level
- Intermediate
- Time
- About 80 minutes
- Nodes need
- 4 vCPU, 6,144 MB
- Smallest plan
- Lite
The scenario
Kestrel Freight has chosen Ansible as its standard automation tool, because playbooks are readable by engineers who don't write Python and because a well-written playbook can be run again and again safely. Your job is to set up the team's first Ansible project for the Leeds routers r1 and r2 (IOS) and the Manchester router xe1 (IOS XE): an inventory, quick ad-hoc checks, a facts report, and a baseline playbook (NTP, syslog, banner, Loopback0) that you'll prove is idempotent.
| Router | Platform | Mgmt address | Site | Loopback0 (to configure) |
|---|---|---|---|---|
| r1 | IOS 15.9 (IOSv) | 10.10.20.11 | Leeds depot | 10.255.0.1/32 |
| r2 | IOS 15.9 (IOSv) | 10.10.20.12 | Leeds depot | 10.255.0.2/32 |
| xe1 | IOS XE 17.3 (CSR 1000v) | 10.10.20.21 | Manchester DC | 10.255.0.3/32 |
NTP and syslog server: 10.10.20.10 (the workstation). Login netops / NetOps-Lab1, exported as $NET_USER and $NET_PASS. Ansible 9.3 (ansible-core 2.16) with the cisco.ios and ansible.netcommon collections is installed on devbox; your project goes in ~/lab/ansible.
What you’ll practise
- Explain how Ansible manages network devices (agentless, network_cli, collections, idempotency)
- Write an inventory with groups, group variables and host variables, and inspect it
- Run ad-hoc commands and a facts playbook against IOS and IOS XE
- Configure devices with ios_config and ios_banner, using check mode, diff, backups and save_when
- Recognise non-idempotent tasks and verify results with ios_command wait_for
The tasks
- How Ansible talks to network devices
- Inventory, groups and variables
- Ad-hoc commands
- A facts playbook that writes reports
- Configure with ios_config: check mode, diff and backups
- Idempotency, and a classic trap
- More modules, host variables and verification
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)
| 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
12 - Ansible for IOS and IOS XE - inventory ad-hoc commands facts and ios_configand 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.