# Ansible ad-hoc win\_ping fails for Windows hosts where direct pywinrm request works

**URL:** <https://forum.ansible.com/t/ansible-ad-hoc-win-ping-fails-for-windows-hosts-where-direct-pywinrm-request-works/26044>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [November 16, 2017, 12:19pm UTC](https://forum.ansible.com/t/ansible-ad-hoc-win-ping-fails-for-windows-hosts-where-direct-pywinrm-request-works/26044 "2017-11-16T12:19:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![macronaute](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@macronaute](https://forum.ansible.com/u/macronaute)\
**Post date:** [November 16, 2017, 12:19pm UTC](https://forum.ansible.com/t/ansible-ad-hoc-win-ping-fails-for-windows-hosts-where-direct-pywinrm-request-works/26044/1 "2017-11-16T12:19:18Z")

</div>

Good morning,

I’m struggling with an annoying issue with my current Ansible setup. Ansible master server is configured and I’m testing basic connectiviy with Linux and Windows nodes.  
Connectivity with Linux nodes is working fine, ad-hoc commands return expected values.

Windows test node is configured with an HTTPs listener (with server certificate installed), firewall is disabled, WinRM service is started and available from other Windows hosts. So far I can successfully issue wman commands locally & remotely from Windows nodes:

`test-wsman -computername winsrv01.domain.lan -Usessl`

> wsmid : [http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd](http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd)  
> ProtocolVersion : [http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd](http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd)  
> ProductVendor : Microsoft Corporation  
> ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

Ansible win\_ping issued from Ansible server fails:

> > ansible 2.4.0.0
> 
> > config file = /etc/ansible/ansible.cfg
> 
> > configured module search path = [u’/home/ansible/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
> 
> > ansible python module location = /usr/lib/python2.7/site-packages/ansible
> 
> > executable location = /usr/bin/ansible
> 
> > python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
> 
> > Using /etc/ansible/ansible.cfg as config file
> 
> > setting up inventory plugins
> 
> > Set default localhost to localhost
> 
> > Parsed /etc/ansible/hosts inventory source with ini plugin
> 
> > Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/ **init**.pyc
> 
> > META: ran handlers
> 
> > Using module file /usr/lib/python2.7/site-packages/ansible/modules/windows/win\_ping.ps1
> 
> > \<winsrv01.DOMAIN.LAN\> ESTABLISH SSH CONNECTION FOR USER:WINUSER@DOMAIN.LAN
> 
> > \<winsrv01.DOMAIN.LAN\> SSH: ansible.cfg set ssh\_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
> 
> > \<winsrv01.DOMAIN.LAN\> SSH: ANSIBLE\_REMOTE\_PORT/remote\_port/ansible\_port set: (-o)(Port=5986)
> 
> > \<winsrv01.DOMAIN.LAN\> SSH: ANSIBLE\_PRIVATE\_KEY\_FILE/private\_key\_file/ansible\_ssh\_private\_key\_file set: (-o)(IdentityFile=“/home/ansible/.ssh/myrsakey”)
> 
> > \<winsrv01.DOMAIN.LAN\> SSH: ANSIBLE\_REMOTE\_USER/remote\_user/ansible\_user/user/-u set: (-o)(User=WINUSER@DOMAIN.LAN)
> 
> > \<winsrv01.DOMAIN.LAN\> SSH: ANSIBLE\_TIMEOUT/timeout set: (-o)(ConnectTimeout=60)
> 
> > \<winsrv01.DOMAIN.LAN\> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/ansible/.ansible/cp/208bf2aa12)
> 
> > \<winsrv01.DOMAIN.LAN\> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=5986 -o ‘IdentityFile=“/home/ansible/.ssh/myrsakey”’ -o User=WINUSER@DOMAIN.LAN -o ConnectTimeout=60 -o ControlPath=/home/ansible/.ansible/cp/208bf2aa12 winsrv01.DOMAIN.LAN ‘/bin/sh -c ‘"’“‘echo ~ && sleep 0’”’"‘’
> 
> > \<winsrv01.DOMAIN.LAN\> (255, ‘’, ‘OpenSSH\_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh\_config\r\ndebug1: /etc/ssh/ssh\_config line 58: Applying options for \*\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket “/home/ansible/.ansible/cp/208bf2aa12” does not exist\r\ndebug2: resolving “winsrv01.DOMAIN.LAN” port 5986\r\ndebug2: ssh\_connect\_direct: needpriv 0\r\ndebug1: Connecting to winsrv01.DOMAIN.LAN [10.0.0.4] port 5986.\r\ndebug2: fd 3 setting O\_NONBLOCK\r\ndebug1: fd 3 clearing O\_NONBLOCK\r\ndebug1: Connection established.\r\ndebug3: timeout: 59999 ms remain after connect\r\ndebug1: identity file /home/ansible/.ssh/myrsakey type 1\r\ndebug1: key\_load\_public: No such file or directory\r\ndebug1: identity file /home/ansible/.ssh/myrsakey-cert type -1\r\ndebug1: Enabling compatibility mode for protocol 2.0\r\ndebug1: Local version string SSH-2.0-OpenSSH\_7.4\r\nConnection timed out during banner exchange\r\n’)
> 
> > winsrv01.DOMAIN.LAN | UNREACHABLE! =\> {
> 
> > “changed”: false,
> 
> > “msg”: “Failed to connect to the host via ssh: OpenSSH\_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh\_config\r\ndebug1: /etc/ssh/ssh\_config line 58: Applying options for \*\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket "/home/ansible/.ansible/cp/208bf2aa12" does not exist\r\ndebug2: resolving "winsrv01.DOMAIN.LAN" port 5986\r\ndebug2: ssh\_connect\_direct: needpriv 0\r\ndebug1: Connecting to winsrv01.DOMAIN.LAN [10.0.0.4] port 5986.\r\ndebug2: fd 3 setting O\_NONBLOCK\r\ndebug1: fd 3 clearing O\_NONBLOCK\r\ndebug1: Connection established.\r\ndebug3: timeout: 59999 ms remain after connect\r\ndebug1: identity file /home/ansible/.ssh/myrsakey type 1\r\ndebug1: key\_load\_public: No such file or directory\r\ndebug1: identity file /home/ansible/.ssh/myrsakey-cert type -1\r\ndebug1: Enabling compatibility mode for protocol 2.0\r\ndebug1: Local version string SSH-2.0-OpenSSH\_7.4\r\nConnection timed out during banner exchange\r\n”,
> 
> > “unreachable”: true
> 
> > }
> 
> pywinrm test script can properly connect to Windows node (after issuing kinit manually on Ansible server to grap a Kerberos ticket):

`python test_winrm.py`

`

# test\_winrm.py

p = Protocol(  
endpoint=‘[https://winsrv01.domain.lan:5986/wsman](https://winsrv01.domain.lan:5986/wsman)’,//  
transport=‘kerberos’,  
username=‘WINUSER@DOMAIN.LAN’,  
server\_cert\_validation=‘ignore’)

shell\_id = p.open\_shell()

command\_id = p.run\_command(shell\_id, ‘hostname’)

std\_out, std\_err, status\_code = p.get\_command\_output(shell\_id, command\_id)

print std\_out  
`

Ansible “/etc/ansible/hosts” file :  
`

[local]  
localhost ansible\_connection=local

[windows]  
winsrv01.DOMAIN.LAN

[linux]  
linuxsrv01.DOMAIN.LAN  
`

Ansible variables "/etc/ansible/group\_vars/windows.yml:  
`

`

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [November 16, 2017, 7:08pm UTC](https://forum.ansible.com/t/ansible-ad-hoc-win-ping-fails-for-windows-hosts-where-direct-pywinrm-request-works/26044/2 "2017-11-16T19:08:40Z")

</div>

It is showing it tried to connect through ssh because there is a typo in your group vars. Change ansible\_connexion: winrm to ansible\_connection: winrm and it should start to use the correct connection plugin.

---

<div class="post-metadata">

**Author:** ![macronaute](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@macronaute](https://forum.ansible.com/u/macronaute)\
**Post date:** [November 17, 2017, 9:24am UTC](https://forum.ansible.com/t/ansible-ad-hoc-win-ping-fails-for-windows-hosts-where-direct-pywinrm-request-works/26044/3 "2017-11-17T09:24:02Z")

</div>

Hi,

You’ve hit the nail right on the head!!  
“Issue” solved…
