AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible Ping Module: Test Host Connectivity & Availability (Guide) — Video Tutorial

How to test host availability with Ansible ping module. Verify SSH connectivity, Python interpreter, and troubleshoot unreachable hosts with examples.

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • Ansible module ping
  • Main parameters and return values
  • Demo
  • Conclusion
  • What ansible.builtin.ping Actually Does
  • Usage Examples
  • Ad-hoc command (most common)
  • Expected output (success)
  • Expected output (failure)
  • In a playbook
Ansible module ping. Today we’re going to talk about the simplest way to test if a managed host is available to receive our commands. I’m Luca Berton and welcome to today’s episode of Ansible Pilot. Ansible module ping Today we’re talking about Ansible module ping. The full name is `ansible.builtin.ping`, which means that is part of the collection of modules “builtin” with ansible and shipped with it. It’s a module pretty stable and out for years. It verify the ability of Ansible to login to the managed host and that there is a Python interpreter that is able to execute our code. So it’s pretty different for the ping in the network context. It's the Linux corresponding to the [Ansible win_ping module](/articles/test-windows-host-availability-ansible-module-win-ping). Main parameters and return values - data _string_ People usually don’t specify any parameters or use the return value. For the parameter, it’s possible to change the behavior from the default “pong” to the “crash” that raises an exception in case of failure. - ping _string_ The return value default is the “pong” string, but you could customize it with the data parameter. Demo Are you ready to make your hands dirty? Let’s jump in a quick live Playbook of a playbook about the ping module. ```yaml --- - name: ping module Playbook hosts: all become: false tasks: - name: test connection ansible.builtin.ping: ``` [code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/tree/master/test%20host%20availability) Conclusion Now you know better the Ansible module ping and you could use it successfully in your playbook. What ansible.builtin.ping Actually Does Despite its name, the Ansible `ping` module does **NOT** perform an ICMP ping (like the `ping` command in your terminal). Instead, it: 1. **Connects** to the managed host via SSH (or WinRM for Windows) 2. **Verifies** that Python is installed and working 3. **Returns** `pong` on success This makes it the perfect **first test** after setting up Ansible to verify your entire connection chain works. Usage Examples Ad-hoc command (most common) ```bash Ping all hosts in inventory ansible all -m ping -i inventory Ping a specific group ansible webservers -m ping -i inventory Ping a single host ansible 192.168.1.100 -m ping -i inventory With specific user and SSH key ansible all -m ping -i inventory -u devops --private-key=~/.ssh/id_rsa ``` Expected output (success) ``` server1 | SUCCESS => { "changed": false, "ping": "pong" } ``` Expected output (failure) ``` server1 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Permission denied", "unreachable": true } ``` In a playbook ```yaml --- - name: Verify all hosts are reachable hosts: all gather_facts: false # ping doesn't need facts tasks: - name: test connection ansible.builtin.ping: register: ping_result - name: show result ansible.builtin.debug: var

About this tutorial

  • Author: Luca Berton
  • Difficulty: Beginner
  • Read time: 6 min
  • Category: installation

Topics covered

Related video tutorials