Ansible – remote_user and ansible_user

There are multiple ways of setting the user which is used when accessing the remote machines.

Ansible will use:

  1. remote_user set in a role / task
  2. remote_user set in a playbook
  3. remote_user set in an inventory file
  4. -u  on the command line
  5. remote_user set in the config files, of which according to the docs for v2.0 the precedence is:
    • ANSIBLE_CONFIG (an environment variable)
    • ansible.cfg (in the current directory)
    • .ansible.cfg (in the home directory)
    • /etc/ansible/ansible.cfg
  6. If your ~/.ssh/config file contains the Host with a User also specified
  7. Your current user

remote_user is not accessible but is settable and inside tasks ansible_user isn’t settable but it is accessible.  For example in a `playbook.yml`

---
- hosts: all
  remote_user: root
  gather_facts: no
  pre_tasks:
    - debug:
        msg: "remote_user is not accessible, ansible_user is {{ ansible_user }}"

I’d guess / I hope the core team will move to one name and drop the other given time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s