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 win_ping Module: Test Windows Host Connectivity (Examples) — Video Tutorial
How to test Windows host availability using Ansible's win_ping module. Includes WinRM setup, troubleshooting connection failures, and inventory configuration.
What You'll Learn
- How to test Windows host availability?
- Ansible module win_ping
- Main Parameters
- Main Return Values
- Conclusion
- Testing Windows Connectivity
- Basic win_ping test
- win_ping in a playbook
- Windows Inventory Setup
- Troubleshooting Connection Failures
Full Tutorial Content
How to test Windows host availability?
Today we're going to talk about the simplest way to test if a Windows-managed host is available to receive our commands.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Ansible module win_ping
Today we're talking about Ansible module win_ping.
The full name is `ansible.windows.win_ping`, which means that is part of the collection of the "windows" modules of ansible. Previously was part of the built-in collection.
It's a module pretty stable and out for years.
It verifies the ability of Ansible to login to the managed host and that there is a shell, usually PowerShell, that is able to execute our code.
So it's pretty different for the ping in the network context.
It's the Windows corresponding to the [Ansible ping module](/articles/test-host-availability-ansible-module-ping).
Main Parameters
- data _string_ - pong
Main Return Values
- ping _string_ success pong
People usually don't specify any parameters or use the return value.
The `win_ping` module usually delivers the `pong` text to the endpoint.
It's possible to personalize the text using the "data" parameter.
The return value is the "ping" string, that contains the same string of the data input parameter.
If we keep the default value we are going to use "pong" as a parameter and as the return value.
## Playbook
Are you ready to make your hands dirty?
Let's jump in a quick live Playbook of a playbook about the win_ping module.
- win_ping.yml
```yaml
---
- name: win_ping module Playbook
hosts: all
become: false
gather_facts: false
tasks:
- name: test connection
ansible.windows.win_ping:
```
[code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/tree/master/test%20host%20availability)
Conclusion
Now you know better the Ansible module win_ping and you could use it successfully in your playbook.
Testing Windows Connectivity
Basic win_ping test
```bash
ansible windows_hosts -m ansible.windows.win_ping -i inventory.yml
```
Expected output:
```
win-server1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
```
win_ping in a playbook
```yaml
---
- name: Test Windows connectivity
hosts: windows
tasks:
- name: Ping Windows hosts
ansible.windows.win_ping:
register: ping_result
- name: Show result
ansible.builtin.debug:
var: ping_result
```
Windows Inventory Setup
```yaml
inventory.yml
all:
children:
windows:
hosts:
win-server1:
ansible_host: 192.168.1.100
win-server2:
ansible_host: 192.168.1.101
vars:
ansible_user: Administrator
ansible_password: "{{ vault_win_password }}"
ansible_connection: winrm
ansible_winrm_transport: ntlm
ansible_winrm_server_cert_validation: ignore
ansible_port: 5986 # HTTPS
```
Troubleshooting Connection Failures
Error: "winrm or requests is not installed"
```bash
pip install pywinrm
```
Error: "connection refused" or time
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 4 min
- Category: installation
Read the full written article: Ansible win_ping Module: Test Windows Host Connectivity (Examples)