remote_user task override not working

Hi,

I have a playbook in which I need to run tasks with different remote users.

This is what the main playlist looks like:

`
#Configure and install all we need

  • hosts: ec2hosts
    gather_facts: true
    remote_user: ec2-user
    sudo: yes
    roles:
  • common

`

And all tasks that have to be run as ec2-user work great.

However, I need to run some of the tasks with a different user, named rails. In order to do this, I specify the remote_user parameter in the task, but for some reason, the task is still executed as ec2-user:

`

  • name: rbenv // basic test
    shell: ls -lah
    remote_user: rails
    sudo: no
    tags: rbenv

`

Resulting in this:

`
TASK: [common | rbenv // basic test] ******************************************
<54.73.67.35> ESTABLISH CONNECTION FOR USER: ec2-user
<54.73.67.35> REMOTE_MODULE command ls -lah #USE_SHELL
<54.73.67.35> EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/bernatrafalesimulet/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ec2-user’, ‘-o’, ‘ConnectTimeout=10’, u’54.73.67.35’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1395246103.49-134656247335216 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1395246103.49-134656247335216 && echo $HOME/.ansible/tmp/ansible-tmp-1395246103.49-134656247335216’”]
<54.73.67.35> PUT /var/folders/mg/1txhtf2d6c1fx4mzmvp9zlbc0000gn/T/tmpcdqUUp TO /home/ec2-user/.ansible/tmp/ansible-tmp-1395246103.49-134656247335216/command
<54.73.67.35> EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/bernatrafalesimulet/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ec2-user’, ‘-o’, ‘ConnectTimeout=10’, u’54.73.67.35’, “/bin/sh -c ‘/usr/bin/python /home/ec2-user/.ansible/tmp/ansible-tmp-1395246103.49-134656247335216/command; rm -rf /home/ec2-user/.ansible/tmp/ansible-tmp-1395246103.49-134656247335216/ >/dev/null 2>&1’”]
changed: [54.73.67.35] => {“changed”: true, “cmd”: "ls -lah ", “delta”: “0:00:00.009791”, “end”: “2014-03-19 16:21:53.695525”, “item”: “”, “rc”: 0, “start”: “2014-03-19 16:21:53.685734”, “stderr”: “”, “stdout”: “total 28K\ndrwx------ 4 ec2-user ec2-user 4.0K Mar 19 16:21 .\ndrwxr-xr-x 4 root root 4.0K Mar 19 16:21 …\ndrwxrwxr-x 3 ec2-user ec2-user 4.0K Mar 19 16:21 .ansible\n-rw-r–r-- 1 ec2-user ec2-user 18 Sep 4 2013 .bash_logout\n-rw-r–r-- 1 ec2-user ec2-user 176 Sep 4 2013 .bash_profile\n-rw-r–r-- 1 ec2-user ec2-user 124 Sep 4 2013 .bashrc\ndrwx------ 2 ec2-user ec2-user 4.0K Feb 17 10:29 .ssh”}

`

Which shows me the list of files of the ec2-user home folder.

Is there any particular reason why I can’t override the remote_user, or what am I doing wrong?

Thanks

I have the same problem, don’t know why, this should be working. I would really appreciate some help there.

Sounds like you are saying the remote_user on the task attribute is not overriding the remote_user on the host.

If you see this behavior on 1.5.3 and later, can you please check to see if you see this behavior on the development branch, and if so, file a bug?

Thank you!

I am seeing this issue with 1.5.5 and now 1.6.2, so I have filed a bug: https://github.com/ansible/ansible/issues/7673

@alex

As noted in the issue above, previously this has been caused by setting the ansible_ssh_user variable in inventory. I have tested the provided playbook with both the 1.6.2 and devel branches and cannot reproduce the issue outside of setting that variable in inventory.

Holding the issue open for now, but most likely the inventory variable is the issue here.

James Cammarata was exactly right - my problem was an inventory issue. In my case, the ansible_ssh_user was not in the inventory file itself, but rather in the group_vars/all file and a more specific group_vars/newservers file (the more specific one overrode to match the play’s remote_user setting, while the group_vars/all value was the same as the task setting, adding to my confusion). I closed the GitHub issue - thanks for pointing me in the right direction.