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

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

RouterPlatformMgmt addressSiteLoopback0 (to configure)
r1IOS 15.9 (IOSv)10.10.20.11Leeds depot10.255.0.1/32
r2IOS 15.9 (IOSv)10.10.20.12Leeds depot10.255.0.2/32
xe1IOS XE 17.3 (CSR 1000v)10.10.20.21Manchester DC10.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

  1. How Ansible talks to network devices
  2. Inventory, groups and variables
  3. Ad-hoc commands
  4. A facts playbook that writes reports
  5. Configure with ios_config: check mode, diff and backups
  6. Idempotency, and a classic trap
  7. 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.

Topology of Ansible for IOS and IOS XE - inventory ad-hoc commands facts and ios_config4 nodes and 1 network, 4 links. Every link is listed as text below the diagram.devboxr1r2xe1Mgmteth0Gi0/0Gi0/0Gi1
4 nodes and 1 network, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in Ansible for IOS and IOS XE: inventory, ad-hoc commands, facts and ios_config, 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 12 - Ansible for IOS and IOS XE - inventory ad-hoc commands facts and ios_config 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.