12

I have been stuck with Ansible window module. I am just trying to ping windows machine.But i get 'connect timeout'

hosts

[windows]
192.168.1.13

group_vars/windows.yaml

ansible_user: raja
ansible_password: myPassword
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

And While I run : ansible windows -vvv -i hosts -m win_ping

Using /etc/ansible/ansible.cfg as config file
<192.168.1.13> ESTABLISH WINRM CONNECTION FOR USER: raja on PORT 5986 TO 192.168.1.13
192.168.1.13 | UNREACHABLE! => {
"changed": false,
"msg": "ssl: HTTPSConnectionPool(host='192.168.1.13', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fcb12024a90>, 'Connection to 192.168.1.13 timed out. (connect timeout=30)'))",
"unreachable": true
}

However I can ping that windows machine using ping 192.168.1.13

rajagopalx
  • 3,012
  • 9
  • 41
  • 52

3 Answers3

20

You need to prep your windows machine for PowerShell remote management, otherwise ansible won't be able to connect to it. For most features to work you will need at least PowerShell 3.0 installed (which is only supported on Windows 7 SP1 or Windows Server 2008 SP1 and later versions), and also run this script, which will not only enable WinRM, but also install some necessary certificates for the connection to work.

Once you donwload the ConfigureRemotingForAnsible.ps1 file the following command from command line should do the job:

powershell.exe -File ConfigureRemotingForAnsible.ps1

SztupY
  • 10,291
  • 8
  • 64
  • 87
  • 1
    At some point, it may be useful to use a versioned link, such as https://github.com/ansible/ansible/blob/c99c3b2b5d396b2cc1d25ad9aa6816aa922ffbc7/examples/scripts/ConfigureRemotingForAnsible.ps1 . Beyond that, I'm wondering, does Ansible run this script automatically? Do folks normally use Ansible (or some other WinRM based tool) to invoke this script? – blong May 18 '17 at 17:32
2

If you using fresh azure vm and aws ec2 and facing issue

"changed": false,
    "msg": "ssl: HTTPSConnectionPool(host='IP Address', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f9650462390>: Failed to establish a new connection: [Errno 111] Connection refused',))",
    "unreachable": true" "

Solution: Just add below rules in windows VM in Inbound rules.

  • WINRM-HTTPS
  • ICMP4
Ice Bear
  • 2,676
  • 1
  • 8
  • 24
0

If you using fresh azure vm and aws ec2 and facing issue

"changed": false, "msg": "ssl: HTTPSConnectionPool(host='IP Address', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f9650462390>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true" " Solution: Just add below rules in windows VM in Inbound rules.

WINRM-HTTPS ICMP4

This is not specific enough. Add these rules where and how.

i255d
  • 20
  • 5