Ansible win_ping Module: Test Windows Host Connectivity (Examples)
By Luca Berton · Published 2024-01-01 · Category: installation
How to test Windows host availability using Ansible's win_ping module. Includes WinRM setup, troubleshooting connection failures, and inventory configuration.

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.See also: Ansible Ping Module: Test Host Connectivity & Availability (Guide)
Ansible module win_ping
Today we're talking about Ansible module win_ping. The full name isansible.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.
Main Parameters
• data _string_ - pongSee also: Add Windows Registry on Windows-like systems - Ansible module win_regedit
Main Return Values
• ping _string_ success pongPeople 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
---
- name: win_ping module Playbook
hosts: all
become: false
gather_facts: false
tasks:
- name: test connection
ansible.windows.win_ping:
Conclusion
Now you know better the Ansible module win_ping and you could use it successfully in your playbook.See also: Ansible Change Windows User Password: win_user Module (Examples)
Testing Windows Connectivity
Basic win_ping test
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
---
- 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
# 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"
pip install pywinrm
Error: "connection refused" or timeout
Enable WinRM on the Windows host (run as Administrator in PowerShell):
# Quick setup (enables WinRM with default settings)
winrm quickconfig -q
# Or use the Ansible-provided script
Invoke-WebRequest -Uri https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -OutFile ConfigureRemotingForAnsible.ps1
.\ConfigureRemotingForAnsible.ps1
Error: "certificate verify failed"
# Option 1: Disable cert validation (testing only)
ansible_winrm_server_cert_validation: ignore
# Option 2: Use HTTP instead of HTTPS (insecure)
ansible_port: 5985
ansible_winrm_scheme: http
Error: "authentication failed"
Check credentials and WinRM auth settings:
# On Windows host — check allowed auth methods
winrm get winrm/config/service/auth
# Enable basic auth if needed
winrm set winrm/config/service/auth @{Basic="true"}
win_ping vs ping
| Module | Target | Protocol | Tests |
|--------|--------|----------|-------|
| ansible.windows.win_ping | Windows | WinRM/PSRP | WinRM + PowerShell |
| ansible.builtin.ping | Linux/Unix | SSH | SSH + Python |
⚠️ Never use ping for Windows hosts — it will fail because it tries SSH + Python.
FAQ
Can I use SSH instead of WinRM?
Yes, if OpenSSH is installed on the Windows host (Windows 10+ / Server 2019+):
ansible_connection: ssh
ansible_shell_type: powershell
How do I test connectivity for all hosts at once?
# Test all hosts (Linux + Windows)
ansible all -m ping -i inventory.yml # Linux
ansible all -m win_ping -i inventory.yml # Windows
# Or group-specific
ansible windows -m win_ping -i inventory.yml
ansible linux -m ping -i inventory.yml
win_ping works but tasks fail — why?
win_ping only tests basic connectivity. Tasks can fail due to:
• Insufficient permissions (need Administrator for many operations)
• Missing Windows features or PowerShell modules
• Execution policy restrictions
Related Articles
• switching users with Ansible become • Ansible Windows administration walkthroughSee also
• Ansible ping Module: Test Host Connectivity (Complete Guide)Category: installation
Watch the video: Ansible win_ping Module: Test Windows Host Connectivity (Examples) — Video Tutorial