The question is simple: what is the difference between
remote_user in Ansible, besides that the first one is set if configuration file and the latter one is set in plays / roles? How do they relate to
--user command line options?
They both seem to be the same. Take a look here:
# the magic variable mapping dictionary below is used to translate
# host/inventory variables to fields in the PlayContext
# object. The dictionary values are tuples, to account for aliases
# in variable names.
MAGIC_VARIABLE_MAPPING = dict(
connection = ('ansible_connection',),
remote_addr = ('ansible_ssh_host', 'ansible_host'),
remote_user = ('ansible_ssh_user', 'ansible_user'),
port = ('ansible_ssh_port', 'ansible_port'),
ansible_user is used when we want to specifiy default SSH user in ansible hosts file where as
remote_user is used in playbook context.
The default ssh user name to use.
and here is an example of using
ansible hosts file:
other1.example.com ansible_connection=ssh ansible_user=mpdehaan
other2.example.com ansible_connection=ssh ansible_user=mdehaan