Content
Today I worked on validating connectivity between an Ansible controller and managed nodes using the Ansible Ping module. Before running any playbooks in a production-like environment, it is important to ensure that Ansible can successfully communicate with the target servers.
๐น What I Learned
Understanding Ansible inventory files
Configuring managed hosts in inventory
Disabling SSH host key checking
Testing connectivity with the Ansible Ping module
Verifying communication between controller and managed nodes
๐น Task Requirement
As per the Nautilus DevOps team requirements, I needed to:
- Use the existing inventory file located at:
/home/thor/ansible/inventory
Configure the inventory with the correct connection details for the application servers.
Ensure password-based SSH connectivity works from the Ansible controller (Jump Host).
Test Ansible connectivity using the Ping module.
Verify successful communication with App Server 3.
๐น Steps I Followed
1. Connected to the Working Directory
Moved into the Ansible project directory:
cd /home/thor/ansible
Verified available files:
ls
Output:
inventory
2. Reviewed the Existing Inventory
Checked the current inventory file:
cat inventory
Output:
stapp01 ansible_ssh_pass=Ir0nM@n
stapp02 ansible_ssh_pass=Am3ric@
stapp03 ansible_ssh_pass=BigGr33n
I noticed that only passwords were defined.
For Ansible to connect successfully, it is a good practice to explicitly define:
Hostname
SSH user
SSH password
I also needed to ensure SSH host key verification would not interrupt automation.
3. Updated the Inventory File
Edited the inventory:
vi inventory
Updated content:
stapp01 ansible_host=stapp01 ansible_user=tony ansible_ssh_pass=Ir0nM@n
stapp02 ansible_host=stapp02 ansible_user=steve ansible_ssh_pass=Am3ric@
stapp03 ansible_host=stapp03 ansible_user=banner ansible_ssh_pass=BigGr33n
[all:vars]
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Saved the file and verified:
cat inventory
๐น Simple Explanation of the Inventory Entries
Host Definition
stapp01 ansible_host=stapp01
Defines the hostname that Ansible will connect to.
SSH User
ansible_user=tony
Specifies the user account Ansible will use when connecting to the remote server.
Examples:
stapp01 โ tony
stapp02 โ steve
stapp03 โ banner
SSH Password
ansible_ssh_pass=Ir0nM@n
Provides the password used for SSH authentication.
Each server has its own password configured.
Global Variables Section
[all:vars]
Applies variables to every host in the inventory.
Disable Host Key Checking
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Disables SSH host key verification prompts.
This prevents Ansible from stopping and asking for confirmation when connecting to a server for the first time.
Complete Inventory
stapp01 ansible_host=stapp01 ansible_user=tony ansible_ssh_pass=Ir0nM@n
stapp02 ansible_host=stapp02 ansible_user=steve ansible_ssh_pass=Am3ric@
stapp03 ansible_host=stapp03 ansible_user=banner ansible_ssh_pass=BigGr33n
[all:vars]
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
๐ In simple terms:
This inventory tells Ansible:
Which servers to manage
Which usernames to use
Which passwords to authenticate with
To skip SSH host key confirmation prompts
๐น 4. Tested Connectivity Using the Ansible Ping Module
Executed the following command:
ansible all -i inventory -m ping
๐น Understanding the Command
Ansible
ansible
Runs an ad-hoc Ansible command.
Target Hosts
all
Targets every host defined in the inventory.
In this case:
stapp01
stapp02
stapp03
Inventory File
-i inventory
Specifies the inventory file to use.
Ping Module
-m ping
Uses Ansible's built-in Ping module.
This module does not send an ICMP ping like the Linux ping command.
Instead, it:
Establishes an SSH connection
Executes Python on the remote host
Returns a response if communication succeeds
๐น 5. Verified Successful Connectivity
Output:
stapp01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
stapp02 | SUCCESS => {
"changed": false,
"ping": "pong"
}
stapp03 | SUCCESS => {
"changed": false,
"ping": "pong"
}
๐น Understanding the Output
SUCCESS
"SUCCESS"
Indicates Ansible successfully connected to the remote server.
Python Interpreter Discovery
"discovered_interpreter_python": "/usr/bin/python3"
Ansible automatically detected the Python interpreter available on the remote host.
Python is required for most Ansible modules to execute.
No Changes Made
"changed": false
The Ping module only verifies connectivity.
It does not modify the remote server.
Therefore, the status remains false.
Pong Response
"ping": "pong"
This confirms:
SSH authentication succeeded
Ansible communication succeeded
The target server is reachable and manageable
๐น Final Verification
All three application servers responded successfully:
stapp01 โ
stapp02 โ
stapp03 โ
This confirmed that the Ansible controller can communicate with all managed nodes and is ready to execute playbooks.
๐น My Understanding
This task helped me understand the importance of inventory configuration in Ansible.
Before any automation can run, Ansible must be able to authenticate and communicate with the target hosts. The Ping module provides a quick and reliable way to validate connectivity before executing playbooks.
๐น What I Found Interesting
I found it interesting that the Ansible Ping module does not perform a traditional network ping. Instead, it validates the complete Ansible communication workflow by establishing an SSH session and executing code on the remote machine.
๐ Full notes: GitHub link
- #ansible-ping-module-usage
- #ansible
- #ansible-playbook
- #ansible-adhoc
- #ansible-automation
- #ansible-inventory-file
- #ansible-project
- #ansible-devops
- #ansible-ping
- #ansible-article
- #devops
- #devops-articles
- #devops-journey
- #devopscommunity
- #devops-trends
- #devops-tools
- #devops-engineer
- #devopsculture
- #devopsjourney
- #devopsproject
- #100daysofdevops
About the author
- Iโm currently working in DevOps and documenting my learning journey along the way. From CI/CD pipelines to cloud and containers, Iโm exploring how modern systems are built and deployed. This blog is where I share what I learn, break down concepts in simple terms, and track my progress. Learning one concept at a time, and trying to apply it practically.
Comments
Join the discussionNo comments yet. Be the first to comment.
100_days_of_devops
Documenting my 100 Days of DevOps journey with hands-on practice from KodeKloud, along with notes, commands, and mini projects