Bootstrap FreeKB - Ansible - Run Ansible against Windows hosts
Ansible - Run Ansible against Windows hosts

Updated:   |  Ansible articles

winrm (Windows Remote Management) is used to make a remote connection to a Windows server. What I typically would do is to first setup my default hosts file or your own inventory file with winrm, something like this.

---
all:
  hosts:
    server1.example.com:
    server2.example.com:
  vars:
    ansible_connection: winrm
    ansible_winrm_transport: basic
    ansible_user: johndoe
    ansible_password: itsasecret
    ansible_port: 5985

 

And then try to ping the Windows hosts using win_ping.

ansible all -m win_ping -i win_hosts.yml 

 

If "winrm or requests is not installed: No module named winrm" is returned, check out my article Resolve "winrm or requests is not installed: No module named winrm".

~]$ ansible all -m win_ping -i win_hosts.yml 
server1.example.com | FAILED! => {
    "msg": "winrm or requests is not installed: No module named winrm"
}

 

Once "winrm or requests is not installed" is no longer being returned, I often next get the following. This is often caused by a firewall between the Ansible server and the Windows host not allowing connections on port 5985.

~]$ ansible all -m win_ping -i win_hosts.yml 
server1.example.com | FAILED! => {
    "changed": false,
    "msg": "basic: HTTPConnectionPool(host='server1.example.com', port=5985): Max retries exceeded with url: /wsman (Caused by ConnectionTimeoutError(<urllib3.connection.HTTPConnection object at 0x7f98e4707a10>, 'Connection to server1.example.com timed out. (connect timeout=30)'))",
    "unreachable": true
}

 

If "Failed to establish a new connection: [Errno 111] Connection refused" is returned, check out my article Resolve "Connection refused" with Windows Host.

~]$ ansible all -m win_ping -i win_hosts.yml 
server1.example.com | FAILED! => {
    "changed": false,
    "msg": "basic: HTTPConnectionPool(host='server1.example.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f98e4707a10>: Failed to establish a new connection: [Errno 111] Connection refused',))",
    "unreachable": true
}

 

If "basic: the specified credentials were rejected by the server" is returned, check out my article Resolve "basic: the specified credentials were rejected by the server".

~]$ ansible all -m win_ping -i win_hosts.yml 
server1.example.com | FAILED! => {
    "changed": false,
    "msg": "basic: the specified credentials were rejected by the server",
    "unreachable": true
}

 

Set winrm to allow unencrypted.

set-netconnectionprofile -networkcategory private
winrm set winrm/config/service '@{AllowUnencrypted="true"}'

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 818e6c in the box below so that we can be sure you are a human.