Lab 1 — Ansible Ping Module
Objective
Lab 1 — Ansible Ping Module
Objective
Ping two worker VMs (worker1 and worker2) from the Master VM (Ansible Controller) using the Ansible ping module.
For this task, three VMs are required:
- 1 Master/Controller VM
- 2 Worker VMs (
worker1andworker2)
Ensure that the SSH service is installed, enabled, and running on both worker VMs before proceeding with the Ansible configuration.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Step 1 — Install Ansible on Master VM
Login to Master VM and install Ansible.
For CentOS/RHEL:
sudo dnf install ansible -y
Verify installation:
ansible --version
Step 2 — Check Connectivity Between VMs
Verify that all VMs can ping each other.
From Master VM:
ping <worker1-ip>
ping <worker2-ip>
Example:
ping 192.168.182.129
ping 192.168.182.130
Step 3 — Create SSH Key on Master VM
Generate SSH key pair on master/controller VM.
ssh-keygen
SSH keys will be created inside:
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
Step 4 — Copy SSH Key to Worker Nodes
Copy public key to both worker VMs.
ssh-copy-id octopus@192.168.182.129
ssh-copy-id octopus@192.168.182.130
Replace octopus with your VM username if different.
Verify passwordless SSH:
ssh octopus@192.168.182.129
ssh octopus@192.168.182.130
Configure SSH on Worker Nodes
Do this on both worker VMs.
Edit SSH daemon configuration:
sudo vi /etc/ssh/sshd_config
Ensure these settings are enabled:
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
Then restart SSH service:
sudo systemctl restart sshd
Verify service status:
sudo systemctl status sshd
Step 5 — Configure Ansible Inventory File
Edit inventory file:
sudo vi /etc/ansible/hosts
Add worker node IPs:
[web]
192.168.182.129
[app]
192.168.182.130
Step 6 — Ping All Worker Nodes
Run Ansible ping command:
ansible all -m ping
Expected Output:
192.168.182.129 | SUCCESS => {
"ping": "pong"
}
192.168.182.130 | SUCCESS => {
"ping": "pong"
}
Step 7 — Ping Specific Group
Ping only web or app group:
ansible web -m ping
ansible app -m ping
Step 8 — Create Group of Groups
Edit inventory file again:
sudo vi /etc/ansible/hosts
Add child groups:

[web]
192.168.182.129
[app]
192.168.182.130
[production:children]
web
[testing:children]
app
[deploy:children]
web
app
Step 9 — Ping Using Child Groups
Ping groups:
ansible production -m ping //Ping productiongroup
ansible testing -m ping //Ping testing group
ansible deploy -m ping //Ping deploy group:
Step 10 — Ping Using VM Hostname
Edit /etc/hosts file on Master VM:
sudo vi /etc/hosts
Add IP and hostname entries:
192.168.182.129 worker1
192.168.182.130 worker2
Now verify hostname resolution:
ping worker1
ping worker2
Step 11 — Add Hostnames in Ansible Inventory
Edit inventory:
sudo vi /etc/ansible/hosts
Replace IPs with hostnames:
[web]
worker1
[app]
worker2
[production:children]
web
[testing:children]
app
[deploy:children]
web
app
Step 12 — Ping Using Hostnames
ansible all -m ping
Expected output:
worker1 | SUCCESS => {
"ping": "pong"
}
worker2 | SUCCESS => {
"ping": "pong"
} 메타데이터
- post_id
- f5fabd395ee2
- slug
- lab-1-ansible-ping-module-f5fabd395ee2
- url
- https://medium.com/@summaiya.mustafa786/lab-1-ansible-ping-module-f5fabd395ee2
- canonical_url
- https://medium.com/@summaiya.mustafa786/lab-1-ansible-ping-module-f5fabd395ee2
- author_url
- https://medium.com/@summaiya.mustafa786
- status
- ok
- fetched_at
- 2026-06-20 20:29:01