Not able to connect to windows machine using Ansible.

I am new to Ansible and trying to connect to windows machine using Ansible. I am getting following error:

`

cic-svr-reiis02.corp.exlservice.com | UNREACHABLE! => {
“changed”: false,
“msg”: “plaintext: HTTPConnectionPool(host=‘cic-svr-reiis02.corp.exlservice.com’, port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError(‘<requests.packages.urllib3.connection.HTTPConnection object at 0x3d76050>: Failed to establish a new connection: [Errno 111] Connection refused’,))”,
“unreachable”: true
}

`

I have made changes in these three files.

  1. Inventory:

[windows] xxx.xxx.xxx.com
1.

  1. Krb5.conf

[realms] XXX.XXX.COM = { kdc = xxx.xxx.xxx.com admin_server = xxx.xxx.xxx.com } [domain_realm] .xxx.xxx.com = XXX.XXX.COM
1.

  1. group_vars/windows.yml

    ansible_ssh_user: user ansible_ssh_pass: password ansible_ssh_port: 5985 ansible_connection: winrm

I am new to this and may have made mistake in the process of connectivity. Any help would be appreciated. Thanks in advance.

From the error message it seems like the WinRM endpoint is not enabled on the remote server hence the Failed to establish a new connection error. Try and use this script to set up the WinRM endpoint on your server https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1.

Once you have done that you should have the following entries in your inventory/group_vars

ansible_user: user@DOMAIN
ansible_password: password
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_cert_validation: ignore