- Netomate
- Posts
- Ansible Mastery Part 3: Your First Network Automation Playbook to Ping Cisco Routers
Ansible Mastery Part 3: Your First Network Automation Playbook to Ping Cisco Routers
Learn how to structure a real Ansible playbook and automate basic reachability checks on Cisco routers in minutes.

Ansible Mastery: Part 3 – Your First Real Playbook to Ping Routers
Welcome back to our Ansible Mastery Journey. If you are new to here , don’t miss to check out part 1 & part 2 before diving into this post. .We have already gone through Ansible basics and different files structure used in Ansible in previous post.
In this post, we will cover :
Understanding the structure and components of an Ansible Playbook
Writing a first playbook to ping routers
How tasks are executed on remote Cisco devices.
Lets dive in.
Create a New Playbook File
I always prefer to start with creating playbook then go ahead with other files around it.
Lets create a new file
anurudh@localhost network_automation_ansible]$ cat 02_ping_router
---
- name: check connectivity to cisco router using ping module
hosts: ios_devices
gather_facts: no
tasks:
- name: ping the router
ping:
[anurudh@localhost network_automation_ansible]$
This is where we’ll define what to run, on which devices, and how.
Remember: Ansible playbooks use YAML, so indentation matters ! Stick to spaces, never tabs.
Understand Ansible Playbook Structure
Ansible Playbook is YAML file which describes what tasks should be executed and on which hosts. Lets understand each line of playbook
---
- name: check connectivity to cisco router using ping module
hosts: ios_devices
gather_facts: no
tasks:
- name: ping the router
ping:
Main Components:-
name : Human readable title .It tells about exactly what this playbook is used for.
hosts: which devices to target from inventory file (hosts.ini). Here ios_devcies is group of hosts on which task will be pushed.
gather_facts: Whether should ansible should collect facts.We will explore about in upcoming posts. currently Lets make it no.
tasks: The task to be performed .
Each task uses ansible module .Here we have used “ping” module in our playbook.
We will talk about module in details in coming posts.
Updated Folder Structure
Here’s your project should look by now.
[anurudh@localhost network_automation_ansible]$ tree
.
├── 01_ping_router_local.yml
├── 02_ping_router
├── ansible.cfg
└── hosts.ini
0 directories, 4 files
[anurudh@localhost network_automation_ansible]$
If you haven’t set these up yet, I recommend going through Part 2 first for further details.
Run the Playbook
Lets run the below playbook with “ansible-playbook” command .This is very basic playbook is used to check reachability of R1 and R2 from master node.
ansible-playbook 02_ping_router
Expected Output:
Task 1: Ping the routers
:
If you see “ok” for each device. Congrats ! your playbook is working .
TASK [ping the router] *************************************************************************************************
ok: [R2]
ok: [R1]
[anurudh@localhost network_automation_ansible]$ ansible-playbook 02_ping_router
PLAY [check connectivity to cisco router using ping module] ************************************************************
TASK [ping the router] *************************************************************************************************
ok: [R2]
ok: [R1]
PLAY RECAP *************************************************************************************************************
R1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
R2 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[anurudh@localhost network_automation_ansible]$
If you see “ok” for each device. Congrats ! your playbook is working .
We have just automated our first network verification tasks.
Thanks for reading Automation! This post is public so feel free to share it.
Action Step for You Today
Just one thing: make sure to go through the concepts and follow along with the tasks. Try to complete them within two days after the post is published.
I’ll guide you, one simple post at a time.
We will deep dive more into Ansible in upcoming posts. Don’t miss to DM or ping me with your queries and comments.
Smiles :)
Anurudh
Reply