Is remote_user used if I want to carry out action as that user rathe than ssh_user?

25 views
Skip to first unread message

John Yeuk Hon Wong

unread,
Sep 15, 2014, 7:40:09 PM9/15/14
to ansible...@googlegroups.com
my ansible_ssh_user is root, but I want a particular role to use a particular user.

For example, create a directory with this remote_user as owner and group. I know I can set the owner-permission using file module, but I was expecting the following to work

- hosts: webservers
  remote_user: "meow"
  roles:
    - clone_repo

  tasks:
    - name: write directory
      file: path=/home/meow/dir state=directory

In addition to directory creation, clone_repo actually clone a repo. But remote_user is not actually used. They are root/root.

Did I misread the doc? http://docs.ansible.com/playbooks_intro.html#hosts-and-users

Thanks

Toshio Kuratomi

unread,
Sep 15, 2014, 8:27:25 PM9/15/14
to ansible...@googlegroups.com
Are you setting ansible_ssh_user = root in the inventory file?  If so, then yep, this is how ansible is designed but it does confuse people.  There's a few bug reports where the concepts are explained:

https://github.com/ansible/ansible/issues/4688
https://github.com/ansible/ansible/issues/4622

The bug reports also point at a workaround that might work for your use case:

- hosts: webservers
  vars:
    - ansible_ssh_user: "meow"
  roles:
    - clone_repo

  tasks:
    - name: write_directory
      file: path=/home/meow/dir state=directory



-Toshio

--
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/63a47337-f61c-4db6-a129-5a6d08b68f09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Sep 15, 2014, 10:24:27 PM9/15/14
to ansible...@googlegroups.com
for a task that you don't want to run as root add:

sudo: yes
sudo_user: nonrootuser
> https://groups.google.com/d/msgid/ansible-project/CAG9juEoteu2BLNRFiCONm%2B9j7Q92i2_%2BcRrmVOXtVAXNaZyvjg%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno
Reply all
Reply to author
Forward
0 new messages