Ansible Lab 2: Validating Router Connectivity and Static Routing with Ansible Automation
Welcome to Lab 2 in the Ansible Automation series. In this lab, we’re building on the basics covered in Lab 1 and taking it a step further by focusing on real-world reachability checks and basic routing configuration using Ansible playbooks.
This lab walks you through setting up your hosts file, testing device reachability with Ansible ad-hoc commands, viewing routing tables across Cisco routers, and applying a static default route where needed. The network environment simulates four routers at different Points of Presence (PoPs) — R1 through R4 — and represents a real service provider scenario.
Lab Scenario
You’re tasked with verifying and adjusting the routing configuration of four routers: R1, R2, R3, and R4. These routers have already been configured with management IPs and credentials:
– **IP Range:** 192.168.47.x
– **Username:** YouTube
– **Password:** YouTube1
– **SSH Port:** 22
As part of this lab, you’ll use ad-hoc Ansible commands to verify SSH access and a set of playbooks to retrieve routing information and configure missing static routes.
Step 1: Ansible Inventory Setup
Start by creating the `hosts` inventory file:
[edge]
R1 ansible_host=192.168.47.21
R2 ansible_host=192.168.47.22
R3 ansible_host=192.168.47.23
R4 ansible_host=192.168.47.24
[edge:vars]
ansible_user=YouTube
ansible_ssh_pass=YouTube1
ansible_port=22
ansible_connection=network_cli
ansible_network_os=cisco.ios.ios
Save this file as `hosts` in your Ansible project directory.
Step 2: Test SSH Connectivity (Ad-Hoc)
We now run a simple Ansible ad-hoc command to validate SSH connectivity:
ansible all -m ping -i hosts
If all devices respond with `pong`, SSH is working.
From the video walkthrough, we saw a successful response from all four routers, confirming the inventory and credentials are valid.

Step 3: Show IP Routing Table
We’ll now use an Ansible playbook to retrieve the routing table using the `ios_command` module.
- name: Show Routing
hosts: edge
gather_facts: no
tasks:
- name: Run show ip route
cisco.ios.ios_command:
commands:
- show ip route
register: output
- name: Display raw output
debug:
var: output.stdout_lines
Run the playbook with:
ansible-playbook -i hosts show-routing.yaml
The output shows full routing tables. From the video, R1 and R2 had a default route present, but R3 and R4 were missing one.

Step 4: Configure Static Default Routes
To fix R3 and R4, we push a default route to all devices. Since R1 and R2 already have the route, Ansible’s idempotent behaviour ensures it’s only applied where needed.
- name: Add Static Route
hosts: edge
gather_facts: no
connection: network_cli
tasks:
- name: Add default route
cisco.ios.ios_config:
lines:
- ip route 0.0.0.0 0.0.0.0 192.168.47.2
Run it with:
ansible-playbook -i hosts default-route.yaml
This adds the default route to R3 and R4, resolving their reachability issue.

Summary
In this lab we:
– Defined an Ansible inventory for four routers
– Validated SSH connectivity with `ping`
– Fetched the routing table via playbook
– Configured a default route where missing
This lab reinforces the benefits of Ansible’s idempotence and gives you confidence in controlling multiple Cisco devices simultaneously.
Pingback: Ansible Lab 03 IP Address Configuration and Loopbacks - RichardKilleen
Good post. I be taught one thing more challenging on completely different blogs everyday. It’s going to always be stimulating to read content material from different writers and observe a bit something from their store. I want to make use of some with the content on my weblog whether you don’t mind. Natually I’l provide you with a hyperlink on your net blog. Thanks for sharing.