I am trying to run ping command on my windows host from linux controller
i created inventory.txt file
[win]
servername
[win:vars]
ansible_user=myusername
ansible_password=password
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_winrm_server_cert_validation=ignore
ansible_port=5986
the error Iam getting is
servername | UNREACHABLE! => {
“changed”: false,
“msg”: “basic: HTTPSConnectionPool(host=‘servernname’, port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError(‘<urllib3.connection.VerifiedHTTPSConnection object at 0x7f8ad0f13f90>: Failed to establish a new connection: [Errno 111] Connection refused’,))”,
“unreachable”: true
}
Simple and easy fix.
Run on the remote computer the following command.
netsh advfirewall firewall add rule name=“Allow WinRM (Http)” dir=in localport=5985 protocol=tcp action=allow enable=yes
netsh advfirewall firewall add rule name=“Allow WinRM (Https)” dir=in localport=5986 protocol=tcp action=allow enable=yes
This should fix your problem.
Kind Regards
Ameya Agashe
thanks for that, but still I am getting same error.
my host machine is w windows 2016 and linux controller is centos and they both were on same corporate domain.
any suggestions…
Not possible, it should work, I had the same issue. What error message are you getting now? ARe you able to ping the server? Can you post the screenshot of Windows firewall for ports 5985 and 5986. Also, important that user " myusername" does exist on that remote Windows Server.
I have done this setup for Windows Server 2016 and SQL Server 2014 SP2 and it works like a charm!
Kind Regards
Ameya Agashe
Ok, I see duplicate firewall rules to delete the one which you just added. Something is odd, are you able to ping them without ansible? Are you able to login to the remote server with username and password defined in inventory?
If that also fails, let us see what others may have to comment as this setup works for me without any issues
Kind Regards
Ameya Agashe
(attachments)
Yes Ameya, I am able to login to the server with same credentials.
I deleted duplicate entries for firewall rules.
(attachments)
Ok, if it is still not working suggest you perform the following activities
- telnet 5985
telnet 5986
- Restart windows
3 Run ansible with -vvv option.
Keep us posted, need to have this resolved as you cannot automate anything in Windows until WInRM is working.
KInd Regards
Ameya Agashe
(attachments)
Ameya, where should i do telnet …
(attachments)
Windows Server you want to test connectivity on that port from your host/Ansible controller.
Ameya
(attachments)
This is on linux server, tried to telnet to windows host
(attachments)
Appears that 5986 is denying the connection, investigate why?
Is WInRM service running on Remote Windows Host?
Ameya
(attachments)
did you manage to solve the problem ?
I run both rules but still not able to run ansible to windows server.
(attachments)
ansible_winrm_transport:ntlm try that instead of ansible_winrm_transport:basic
I haven’t tried yet, I am working with my netops and infra team about it.