# Ansible unable to winrm to Windows Server 2012

**URL:** <https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782>\
**Category:** Ansible Project\
**Tags:** windows, rhel\
**Created:** [February 27, 2019, 2:38am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782 "2019-02-27T02:38:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Tan](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@Eric\_Tan](https://forum.ansible.com/u/Eric_Tan)\
**Post date:** [February 27, 2019, 2:38am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782/1 "2019-02-27T02:38:44Z")

</div>

##### SUMMARY

1. Using Python 2.7 in RHEL7
2. Executed powershell script in windows machine ConfigureRemotingForAnsible.ps1
3. Configured yml file to the below:

- name: hit windows test instance  
hosts: “tag\_class\_windows\_{{ env }}\_{{ ec2\_class }}”  
vars:  
ansible\_user: Administrator  
ansible\_password: {{ password }}  
ansible\_port: 5986  
ansible\_connection: winrm  
ansible\_winrm\_server\_cert\_validation: ignore  
ansible\_winrm\_operation\_timeout\_sec: 60  
ansible\_winrm\_read\_timeout\_sec: 70  
tasks:

- ec2:  
state: ‘absent’  
instance\_ids: {{ instance\_id }}’  
ec2\_region: ‘{{ ec2\_region }}’  
delegate\_to: localhost

Error encountered:  
fatal: [xxx.xxx.xxx.xxx]: UNREACHABLE! =\> {“changed”: false, “msg”: “ssl: HTTPSConnectionPool(host=‘localhost’, port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError(‘\<urllib3.connection.VerifiedHTTPSConnection object at 0x7fefb0fdf3d0\>: Failed to establish a new connection: [Errno 111] Connection refused’,))”, “unreachable”: true}

##### ISSUE TYPE

- Bug Report

##### COMPONENT NAME

winrm

##### ANSIBLE VERSION

ansible 2.4.3.0

##### CONFIGURATION

HOST\_KEY\_CHECKING(/etc/ansible/ansible.cfg) = False

##### OS / ENVIRONMENT

Host: RHEL 7  
WinRM to Windows 2012

##### STEPS TO REPRODUCE

ansible-playbook -i /etc/ansible/ec2.py hitwin.yml --extra-vars “ec2\_class=appservers env=test”

- name: hit windows test instance  
hosts: “tag\_class\_windows\_{{ env }}\_{{ ec2\_class }}”  
vars:  
ansible\_user: Administrator  
ansible\_password: {{ password }}  
ansible\_port: 5986  
ansible\_connection: winrm  
ansible\_winrm\_server\_cert\_validation: ignore  
ansible\_winrm\_operation\_timeout\_sec: 60  
ansible\_winrm\_read\_timeout\_sec: 70  
tasks:

- ec2:  
state: ‘absent’  
instance\_ids: {{ instance\_id }}’  
ec2\_region: ‘{{ ec2\_region }}’  
delegate\_to: localhost

##### EXPECTED RESULTS

Expected success to win rm and shutdown server

##### ACTUAL RESULTS

PLAY [hit windows test instance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [xxx.xxx.xxx.xxx]

TASK [ec2] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [xxx.xxx.xxx.xxx]: UNREACHABLE! =\> {“changed”: false, “msg”: “ssl: HTTPSConnectionPool(host=‘localhost’, port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError(‘\<urllib3.connection.VerifiedHTTPSConnection object at 0x7fefb0fdf3d0\>: Failed to establish a new connection: [Errno 111] Connection refused’,))”, “unreachable”: true}

```auto
to retry, use: --limit @/home/ec2-user/ansible-netenv/hitwin.retry

```

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
xxx.xxx.xxx.xxx : ok=1 changed=0 unreachable=1 failed=0

---

<div class="post-metadata">

**Author:** ![Ameya\_Agashe](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@Ameya\_Agashe](https://forum.ansible.com/u/Ameya_Agashe)\
**Post date:** [February 27, 2019, 2:51am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782/2 "2019-02-27T02:51:14Z")

</div>

Run below in PowerShell and it should keep you going:

netsh advfirewall firewall add rule name=“Allow WinRM (Https)” dir=in localport=5986 protocol=tcp action=allow enable=yes

Thanks and Regards,  
Ameya Agashe

---

<div class="post-metadata">

**Author:** ![Eric\_Tan](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@Eric\_Tan](https://forum.ansible.com/u/Eric_Tan)\
**Post date:** [February 27, 2019, 3:38am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782/3 "2019-02-27T03:38:07Z")

</div>

Hi Ameya,

thanks for your response!  
I forgot to add that the firewall is already opened in my issue but it still doesnt work.  
I read somewhere that it has to do with the cipher suite that RHEL7 and Windows default uses.

Do you have any idea about this?

---

<div class="post-metadata">

**Author:** ![Ameya\_Agashe](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@Ameya\_Agashe](https://forum.ansible.com/u/Ameya_Agashe)\
**Post date:** [February 27, 2019, 3:43am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782/4 "2019-02-27T03:43:23Z")

</div>

Hi Tan,

Not aware of the issue you referring about, under normal circumstances the command I gave should work. Have you tried running playbook in debug mode to see what is happening under the cover? place “-vvv” at the last of command line.

Regards  
Ameya Agashe

---

<div class="post-metadata">

**Author:** ![Eric\_Tan](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@Eric\_Tan](https://forum.ansible.com/u/Eric_Tan)\
**Post date:** [February 27, 2019, 3:49am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782/5 "2019-02-27T03:49:00Z")

</div>

Hi Ameya,

Below is the debug information. By the way, the localhost is RHEL7 OS and the ec2 we are trying to winrm is Windows Server 2012.

---

<div class="post-metadata">

**Author:** ![Ameya\_Agashe](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@Ameya\_Agashe](https://forum.ansible.com/u/Ameya_Agashe)\
**Post date:** [February 27, 2019, 4:02am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782/6 "2019-02-27T04:02:31Z")

</div>

Hi Tran,

Still, think it is Firewall only, can you double check?

Thanks  
Ameya

---

<div class="post-metadata">

**Author:** ![Eric\_Tan](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@Eric\_Tan](https://forum.ansible.com/u/Eric_Tan)\
**Post date:** [February 27, 2019, 5:50am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782/7 "2019-02-27T05:50:31Z")

</div>

Hi Ameya,

To verify if i can reach the server, i used win\_ping

> **(attachments)**
>
> ![Capture.PNG](https://us1.discourse-cdn.com/ansible/original/2X/0/063ec442e60b6cdb63d3cd1be00ff54de8a59bce.png)

---

<div class="post-metadata">

**Author:** ![Ameya\_Agashe](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@Ameya\_Agashe](https://forum.ansible.com/u/Ameya_Agashe)\
**Post date:** [February 27, 2019, 6:02am UTC](https://forum.ansible.com/t/ansible-unable-to-winrm-to-windows-server-2012/29782/8 "2019-02-27T06:02:10Z")

</div>

Strange, running out of ideas, anyone can think of anything else?

Kind Regards,  
Ameya Agashe

> **(attachments)**
>
> ![Capture.PNG](https://us1.discourse-cdn.com/ansible/original/2X/0/063ec442e60b6cdb63d3cd1be00ff54de8a59bce.png)
