Hi, I’m new to ansible and have been unable to achieve the following:
I would like to include tasks in my playbook and run them with another user that’s running the playbook.
I have tried the following, without success:
`
include: mytasks.yml remote_user=toto
`
I have also tried this (from the documentation)
`
include: mytasks.yml
vars:
remote_user: toto
`
but again, when running the playbook, the tasks are executed with the playbook remote user and not the one defined next to the include.
I’m using ansible 1.5.4.
Is there anyway to do this ? or do I have to specify the remote_user for each and every task in the tasks file ?
thanks a lot,
regards,
ozb.
While a keyword in ansible for a task or play, remote_user is not a magic variable here any more than “antelope_jetpack” is likely to work. It’s just the wrong variable name is all
You can set “ansible_ssh_user” in inventory as a variable to control the remote user, which could also be set here.
Generally people set this at play level instead.
hosts: postgresql_steps
remote_user: postgres
Etc
Though usually most people would do this kind of thing with “sudo_user” instead, and just pass the connecting user on the command line or assume the default.