# Ansible WinRM shows 401 Unauthorized when pywinrm works with no problem

**URL:** <https://forum.ansible.com/t/ansible-winrm-shows-401-unauthorized-when-pywinrm-works-with-no-problem/19578>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [October 21, 2015, 4:37pm UTC](https://forum.ansible.com/t/ansible-winrm-shows-401-unauthorized-when-pywinrm-works-with-no-problem/19578 "2015-10-21T16:37:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tianwei\_Liu](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@Tianwei\_Liu](https://forum.ansible.com/u/Tianwei_Liu)\
**Post date:** [October 21, 2015, 4:37pm UTC](https://forum.ansible.com/t/ansible-winrm-shows-401-unauthorized-when-pywinrm-works-with-no-problem/19578/1 "2015-10-21T16:37:40Z")

</div>

Hi,

I am having this weird problem that my ansible will always show 401 error when trying to connect my windows machine via winrm. Although I can use pywinrm with no problem at all authenticating with the exact same account and password.

My inventory:

[windows]  
192.168.2.3

[windows:vars]  
ansible\_ssh\_user=ansible  
ansible\_ssh\_password=ansible  
ansible\_ssh\_port=5986  
ansible\_connection=winrm

I can run the example from: [https://github.com/diyan/pywinrm](https://github.com/diyan/pywinrm) and get results with no problem but my ansible ping results in 401.

$ ansible windows -i inventory.yml -m win\_ping -vvvv

\<192.168.2.3\> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO 192.168.2.3

\<192.168.2.3\> WINRM CONNECT: transport=plaintext endpoint=[https://192.168.2.3:5986/wsman](https://192.168.2.3:5986/wsman)

\<192.168.2.3\> WINRM CONNECTION ERROR: 401 Unauthorized.

192.168.2.3 | FAILED =\> 401 Unauthorized.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [October 22, 2015, 2:26pm UTC](https://forum.ansible.com/t/ansible-winrm-shows-401-unauthorized-when-pywinrm-works-with-no-problem/19578/2 "2015-10-22T14:26:54Z")

</div>

Which ansible version are you using? (run ‘ansible --version’ to find out).

Generally 401 means the expected password doesn’t match the one you supplied.

You could check the event log on the windows machine for more information.

Also, did you run [https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1](https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1) ?

---

<div class="post-metadata">

**Author:** ![Aleksander\_Sjafjell](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Aleksander\_Sjafjell](https://forum.ansible.com/u/Aleksander_Sjafjell)\
**Post date:** [November 1, 2015, 9:18pm UTC](https://forum.ansible.com/t/ansible-winrm-shows-401-unauthorized-when-pywinrm-works-with-no-problem/19578/3 "2015-11-01T21:18:58Z")

</div>

Hi, Tianwei Liu. Did you find a solution for this problem?

I am experiencing the exact same result. I can run winrm-commands directly, but Ansible gives me 401, access denied. If i run

`  
ansible all -i windows.yml -m win\_ping -vvvv

`

Where windows.yml is as follows:

`

[all]  
192.168.50.4

[all:vars]  
ansible\_user=“vagrant”  
ansible\_password=“vagrant”  
ansible\_port=“5985”  
ansible\_connection=“winrm”

`

I get the following output:

`

\<192.168.50.4\> ESTABLISH WINRM CONNECTION FOR USER: aas on PORT 5986 TO 192.168.50.4  
\<192.168.50.4\> WINRM CONNECT: transport=plaintext endpoint=[https://192.168.50.4:5986/wsman](https://192.168.50.4:5986/wsman)  
\<192.168.50.4\> WINRM CONNECTION ERROR: 401 Unauthorized.

`

What i find a bit weird is that user is specified as ‘aas’ (my OSX user). It seems that the username from inventory file is not used. All help apprecieated.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 2, 2015, 11:55am UTC](https://forum.ansible.com/t/ansible-winrm-shows-401-unauthorized-when-pywinrm-works-with-no-problem/19578/4 "2015-11-02T11:55:38Z")

</div>

I wonder if this is still looking for the older name  
ansible\_ssh\_user instead of ansible\_user ?

You don’t mention which version of ansible you are using.

I haven’t checked but if it is older than current dev I think you will need to use the name  
ansible\_ssh\_user in your group vars

same thing will apply for

ansible\_ssh\_password  
and  
ansible\_ssh\_port

even though winrm is not using ssh for the transport, the settings needed ssh in them for historical reasons.

Jon

---

<div class="post-metadata">

**Author:** ![kevin.e.kenny](https://avatars.discourse-cdn.com/v4/letter/k/d07c76/32.png) [@kevin.e.kenny](https://forum.ansible.com/u/kevin.e.kenny)\
**Post date:** [November 12, 2015, 9:16pm UTC](https://forum.ansible.com/t/ansible-winrm-shows-401-unauthorized-when-pywinrm-works-with-no-problem/19578/5 "2015-11-12T21:16:25Z")

</div>

Try changing:

ansible\_ssh\_password=ansible

to

ansible\_ssh\_pass=ansible

That tripped me up with 1.9.4.

Same thing would apply to your windows.yml.

Kev

---

<div class="post-metadata">

**Author:** ![Krishna\_Chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@Krishna\_Chaitanya](https://forum.ansible.com/u/Krishna_Chaitanya)\
**Post date:** [May 13, 2016, 12:21am UTC](https://forum.ansible.com/t/ansible-winrm-shows-401-unauthorized-when-pywinrm-works-with-no-problem/19578/6 "2016-05-13T00:21:56Z")

</div>

Hi,

I am facing same issue even after changing ansible\_ssh\_password to ansible\_password.

Facing issue with 401 unauthorized error for winrm connection. Need help
