remote_user task override not working

350 views
Skip to first unread message

Bernat Ràfales

unread,
Mar 19, 2014, 12:31:58 PM3/19/14
to ansible...@googlegroups.com
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

Tonatiuh IIII

unread,
Apr 2, 2014, 10:03:18 AM4/2/14
to ansible...@googlegroups.com
I have the same problem, don't know why, this should be working. I would really appreciate some help there.

Michael DeHaan

unread,
Apr 2, 2014, 4:04:30 PM4/2/14
to ansible...@googlegroups.com
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!




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f3d705d9-1cc2-43e4-9df6-1cbe7a6c387a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Alex Dupuy

unread,
Jun 5, 2014, 9:16:08 AM6/5/14
to ansible...@googlegroups.com
On Wednesday, April 2, 2014 10:04:30 PM UTC+2, Michael DeHaan wrote:
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?


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

James Cammarata

unread,
Jun 5, 2014, 12:26:50 PM6/5/14
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Alex Dupuy

unread,
Jun 5, 2014, 5:33:59 PM6/5/14
to ansible...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages