One thing I’ve noticed, and have not been able to find a resolution to via IRC or reading the source, is how to make the remote_user var set at the play level available to all roles in the play. It’s useful to have this for a few tasks, and while it’s easy enough to define it under the roles, it’s just c/p’ing code at that point and doesn’t feel right or as clean as the rest of Ansible can be. I think this would be really useful to add as behavior.
Not sure what you mean. When set at play level, all tasks by default will use that remote_user. you can override on specific tasks with different remote_user. Of course unless hostvars override with ansible_ssh_user
Did you want to reference that variable in a template somewhere?
I was running a playbook and referencing remote_user in a file under /roles/my_role/tasks/deploy.yml, (included in /roles/my_role/tasks/main.yml) and Ansible was giving me an error that {{remote_user}} did not exist.
This isn’t an output variable that you can use in a template anywhere.
You may be interested in the value of {{ ansible_ssh_user }}
Michael,
This is super helpful. Thanks. Since you would be in the know, is there any reason that remote_user is not passed down to roles, etc.? It seems like it would be something useful to have access to, and was a surprise when I didn’t.
It is – it’s called ansible_ssh_user.
Originally the variable in ansible was called “user” but to avoid confusion when used with the “user” module, remote_user is an alias.
Michael DeHaan <michael@ansible.com> napisał:
It is -- it's called ansible_ssh_user.
Originally the variable in ansible was called "user" but to avoid
confusion
when used with the "user" module, remote_user is an alias.
You mean "task parameter" (or are they called arguments?), and not "variable", right?
I do. Parameter is probably a good word.