# remote\_user on task is not working, how can I get troubleshooting information?

**URL:** <https://forum.ansible.com/t/remote-user-on-task-is-not-working-how-can-i-get-troubleshooting-information/26193>\
**Category:** Ansible Project\
**Created:** [December 3, 2017, 6:30am UTC](https://forum.ansible.com/t/remote-user-on-task-is-not-working-how-can-i-get-troubleshooting-information/26193 "2017-12-03T06:30:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gordonmessmer](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gordonmessmer/32/1925_2.png) [@gordonmessmer](https://forum.ansible.com/u/gordonmessmer)\
**Post date:** [December 3, 2017, 6:30am UTC](https://forum.ansible.com/t/remote-user-on-task-is-not-working-how-can-i-get-troubleshooting-information/26193/1 "2017-12-03T06:30:39Z")

</div>

I have a task defined that sets “remote\_user” which has mysteriously started connecting as “root” instead of my own user account. I’ve been using this task for some time, and haven’t made any changes that appear relevant, recently. I’m also using it in a test environment where it is working normally, and where I can’t find any relevant differences.

When I run the playbook containing this task with -vvv, I see ansible connecting as root, the relevant output is below.

Ansible version:  
$ rpm -q ansible  
ansible-2.4.1.0-1.el7.noarch

Where can I look in the code to try to determine why remote\_user isn’t being set properly?

The task is defined:

- name: check for kerberos ticket  
shell: “klist | egrep -q ‘Default principal: ({{ "|".join(admin\_users) }})@’”  
register: has\_kerberos\_admin  
ignore\_errors: True  
delegate\_to: “{{ ipa\_server }}”  
remote\_user: “{{ lookup(‘env’, ‘USER’) }}”  
tags: configuration

Output from -vvv:

TASK [ipa-admin-command : check for kerberos ticket] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/gordon/ansible-example/roles/ipa-admin-command/tasks/main.yml:1  
Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py  
\<[ds-20170921.private.example.net](http://ds-20170921.private.example.net)\> ESTABLISH SSH CONNECTION FOR USER: root  
\<[ds-20170921.private.example.net](http://ds-20170921.private.example.net)\> SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=60s -o GSSAPIAuthentication=yes -o GSSAPIDelegateCredentials=yes -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/gordon/.ansible/cp/923a4e9819 [ds-20170921.private.example.net](http://ds-20170921.private.example.net) ‘/bin/sh -c ‘"’"’/usr/bin/python && sleep 0’“'”‘’  
\<[ds-20170921.private.example.net](http://ds-20170921.private.example.net)\> (1, ‘\n{“changed”: true, “end”: “2017-12-02 19:26:10.012527”, “stdout”: “”, “cmd”: “klist | egrep -q 'Default principal: (gordon)@'”, “failed”: true, “delta”: “0:00:00.012965”, “stderr”: “klist: Credentials cache keyring 'persistent:0:0' not found”, “rc”: 1, “invocation”: {“module\_args”: {“warn”: true, “executable”: null, “\_uses\_shell”: true, “\_raw\_params”: “klist | egrep -q 'Default principal: (gordon)@'”, “removes”: null, “creates”: null, “chdir”: null, “stdin”: null}}, “start”: “2017-12-02 19:26:09.999562”, “msg”: “non-zero return code”}\n’, ‘’)

---

<div class="post-metadata">

**Author:** ![gordonmessmer](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gordonmessmer/32/1925_2.png) [@gordonmessmer](https://forum.ansible.com/u/gordonmessmer)\
**Post date:** [December 3, 2017, 6:55am UTC](https://forum.ansible.com/t/remote-user-on-task-is-not-working-how-can-i-get-troubleshooting-information/26193/2 "2017-12-03T06:55:00Z")

</div>

Setting “remote\_user” statically does not change the outcome. With “remote\_user: gordon”, ansible still connects as “root”.

---

<div class="post-metadata">

**Author:** ![gordonmessmer](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gordonmessmer/32/1925_2.png) [@gordonmessmer](https://forum.ansible.com/u/gordonmessmer)\
**Post date:** [December 3, 2017, 7:13am UTC](https://forum.ansible.com/t/remote-user-on-task-is-not-working-how-can-i-get-troubleshooting-information/26193/3 "2017-12-03T07:13:26Z")

</div>

ansible.cfg does contain:

[defaults]  
remote\_user=root

but that file has the same contents on the test system, where the same playbook works, and ansible connects as the user named in the task’s “remote\_user” setting.

---

<div class="post-metadata">

**Author:** ![gordonmessmer](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gordonmessmer/32/1925_2.png) [@gordonmessmer](https://forum.ansible.com/u/gordonmessmer)\
**Post date:** [December 3, 2017, 5:27pm UTC](https://forum.ansible.com/t/remote-user-on-task-is-not-working-how-can-i-get-troubleshooting-information/26193/4 "2017-12-03T17:27:27Z")

</div>

If I set “strategy: debug” for the play and “p vars” there are a number of settings in the broken system which aren’t set to any value on the system that works.

‘vars’: {…  
‘ansible\_delegated\_vars’: {u’[ds-20170921.private.example.net](http://ds-20170921.private.example.net)’: {…  
‘ansible\_connection’: u’smart’,  
‘ansible\_delegated\_host’: u’[ds-20170921.private.example.net](http://ds-20170921.private.example.net)’,  
‘ansible\_host’: u’[ds-20170921.private.example.net](http://ds-20170921.private.example.net)’,  
…  
‘ansible\_port’: None,  
‘ansible\_user’: u’root’,

Those 5 values in ansible\_delegated\_vars[the delegated\_to host] don’t have any value on the working system. However, the working system has at least one value that the broken one does not:

{…  
‘ansible\_current\_hosts’: [u’[network-2017120101.tutorial.example.net](http://network-2017120101.tutorial.example.net)’],

---

<div class="post-metadata">

**Author:** ![gordonmessmer](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gordonmessmer/32/1925_2.png) [@gordonmessmer](https://forum.ansible.com/u/gordonmessmer)\
**Post date:** [December 3, 2017, 6:22pm UTC](https://forum.ansible.com/t/remote-user-on-task-is-not-working-how-can-i-get-troubleshooting-information/26193/5 "2017-12-03T18:22:33Z")

</div>

SOLVED:

This problem appears to have been caused by the introduction of dynamic inventory. I pull a list of hosts from libvirt (virsh list --name), and on the broken system, one VM has a name with a typo. It does not match the host’s name in DNS, and the name given in the delegate\_to setting (the ipa\_server variable).

The problem appears to be that ansible allows you to delegate\_to a host that doesn’t appear in your inventory, but that connection doesn’t behave like a connection to a host that _is_ in the inventory. Among other things, you can’t set “remote\_user” for a task that is delegated to a host that doesn’t appear in the inventory.

I’ll file a bug report later.
