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

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

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

for a task that you don't want to run as root add:

sudo: yes
sudo_user: nonrootuser