# "Kerberos-based authentication was failed. Code 401" - but I've already acquired a valid ticket

**URL:** <https://forum.ansible.com/t/kerberos-based-authentication-was-failed-code-401-but-ive-already-acquired-a-valid-ticket/20767>\
**Category:** Ansible Project\
**Tags:** azure, windows, ubuntu\
**Created:** [March 4, 2016, 7:57am UTC](https://forum.ansible.com/t/kerberos-based-authentication-was-failed-code-401-but-ive-already-acquired-a-valid-ticket/20767 "2016-03-04T07:57:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mateusz.blaszkowski](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@mateusz.blaszkowski](https://forum.ansible.com/u/mateusz.blaszkowski)\
**Post date:** [March 4, 2016, 7:57am UTC](https://forum.ansible.com/t/kerberos-based-authentication-was-failed-code-401-but-ive-already-acquired-a-valid-ticket/20767/1 "2016-03-04T07:57:10Z")

</div>

Hi,

I’m struggling with 401 authentication error. I’ve got Windows Server 2012 R2 and Ubuntu 14.04 machine (with Ansible v2.0.0.2). I’m trying to authenticate as test user (who belongs to Domain Admins group). This is my inventory\_windows.yml file:

[windows]  
10.91.96.60 ansible\_user=test@MYCLOUD.LOCAL ansible\_port=5986 ansible\_connection=winrm

And the way I execute Ansible:

ansible windows -i inventory\_windows.yml -m win\_ping -vvvvvv

Using /etc/ansible/ansible.cfg as config file  
Loaded callback minimal of type stdout, v2.0  
\<10.91.96.60\> ESTABLISH WINRM CONNECTION FOR USER: test@MYCLOUD.LOCAL on PORT 5986 TO 10.91.96.60  
\<10.91.96.60\> WINRM CONNECT: transport=kerberos endpoint=[https://10.91.96.60:5986/wsman](https://10.91.96.60:5986/wsman)  
\<10.91.96.60\> WINRM CONNECTION ERROR: the username/password specified for this server was incorrect  
Traceback (most recent call last):  
File “/usr/lib/pymodules/python2.7/ansible/plugins/connection/winrm.py”, line 138, in \_winrm\_connect  
protocol.send\_message(‘’)  
File “/usr/local/lib/python2.7/dist-packages/winrm/protocol.py”, line 193, in send\_message  
return self.transport.send\_message(message)  
File “/usr/local/lib/python2.7/dist-packages/winrm/transport.py”, line 301, in send\_message  
raise WinRMTransportError(‘kerberos’, error\_message)  
WinRMTransportError: 500 WinRMTransport. Kerberos-based authentication was failed. Code 401

I know that I should acquire a ticket first. Here’s how I do this:

kinit test@MYCLOUD.LOCAL  
Password for test@MYCLOUD.LOCAL:

klist  
Ticket cache: FILE:/tmp/krb5cc\_0  
Default principal: test@MYCLOUD.LOCAL

Valid starting Expires Service principal  
03/04/2016 16:29:19 03/05/2016 02:29:19 krbtgt/MYCLOUD.LOCAL@MYCLOUD.LOCAL  
renew until 03/05/2016 16:29:20

I thought that if I acquired a ticket, than there should be no authentication errors, but apparently I’m wrong.

Note that I’ve already (as described here: [troubleshooting-kerberos-connections](http://docs.ansible.com/ansible/intro_windows.html#troubleshooting-kerberos-connections)):

1. Synchronized the time between Linux and Windows machine.
2. Verified that my forward and reverse DNS lookups are working fine. nslookup 10.91.96.60 returns the correct FQDN:  
nslookup 10.91.96.60  
Server: 10.91.97.101  
Address: 10.91.97.101#53

60.96.91.10.in-addr.arpa name = winhost.mycloud.local.

1. Enabled `AllowUnencrypted` option on Windows machine and tried with ansible\_winrm\_scheme=http.

One of the things I’m not sure is this:  
“Ensure that the Ansible controller has a properly configured computer account in the domain.”

Could someone explain this? I’ve created ‘azure’ computer account in AD (‘azure’ is the hostname of my Ubuntu machine). Is this enough?

Any help would be much appreciated!

---

<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:** [March 5, 2016, 2:12pm UTC](https://forum.ansible.com/t/kerberos-based-authentication-was-failed-code-401-but-ive-already-acquired-a-valid-ticket/20767/2 "2016-03-05T14:12:07Z")

</div>

I’d recommend using the hostname, rather than the ip address of the windows machine you want to connect to in your inventory. Kerberos/Active Directory seems to be intended to work with host and domain names.

I would also check that ping yourhost and ping yourhost.mycloud.local return the correct ip for the host (this is what I meant by dns working ‘both ways’).

Also I’d suggest trying without setting ansible\_winrm\_scheme=http - if only because I have it working without this, although I believe it should work either way.

One last thought, have you run the [https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1](https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1) script on the remote host?

You can check if kerberos support is on if you run

winrm get winrm/config

and look for keberos under Serivce → Auth

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![mateusz.blaszkowski](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@mateusz.blaszkowski](https://forum.ansible.com/u/mateusz.blaszkowski)\
**Post date:** [March 8, 2016, 8:59am UTC](https://forum.ansible.com/t/kerberos-based-authentication-was-failed-code-401-but-ive-already-acquired-a-valid-ticket/20767/3 "2016-03-08T08:59:48Z")

</div>

Thank you very much for your help. I have already done everything you suggested - I tried to use hostnames instead of IPs, checked ‘both way’ DNS configuration, used HTTP instead of HTTPS, verified that Kerberos and HTTP are enabled. The Powershell scripts was executed on the remote host as well. Unfortunately nothing helped. I have provisioned another Active Directory VM and created new domain - this time it worked as expected. It’s just a pity I don’t know what was wrong in my previous configuration. Thank you anyway!
