# Remote\_user is declared in playbook file and ansible\_user is declared in inventory file

**URL:** <https://forum.ansible.com/t/remote-user-is-declared-in-playbook-file-and-ansible-user-is-declared-in-inventory-file/2507>\
**Category:** Get Help\
**Created:** [November 22, 2023, 8:38am UTC](https://forum.ansible.com/t/remote-user-is-declared-in-playbook-file-and-ansible-user-is-declared-in-inventory-file/2507 "2023-11-22T08:38:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanhnguyen](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lanhnguyen](https://forum.ansible.com/u/lanhnguyen)\
**Post date:** [November 22, 2023, 8:38am UTC](https://forum.ansible.com/t/remote-user-is-declared-in-playbook-file-and-ansible-user-is-declared-in-inventory-file/2507/1 "2023-11-22T08:38:46Z")

</div>

remote\_user is declared in playbook file and ansible\_user is declared in inventory file. Which user is used to run playbook file?  
become: true and remote\_user always go tother?

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [November 22, 2023, 3:22pm UTC](https://forum.ansible.com/t/remote-user-is-declared-in-playbook-file-and-ansible-user-is-declared-in-inventory-file/2507/2 "2023-11-22T15:22:03Z")

</div>

> remote\_user is declared in playbook file and ansible\_user is declared in inventory file. Which user is used to run playbook file?

Variables take precedence over playbook keywords, see [Controlling how Ansible behaves: precedence rules — Ansible Documentation](https://docs.ansible.com/ansible/latest/reference_appendices/general_precedence.html#precedence-categories).

If a connection plugin accepts multiple variables (or multiple cli/ini/env options), for example, the ssh connection uses the variables `ansible_ssh_user` or `ansible_user`, whichever is listed last has higher priority.

Given that, the configuration options for the ssh `remote_user` option [ansible.builtin.ssh connection – connect via SSH client binary — Ansible Documentation](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-remote_user) have the precedence (lowest to highest):

- INI entry: `[defaults] remote_user = VALUE`
- Environment variable: [`ANSIBLE_REMOTE_USER`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#envvar-ANSIBLE_REMOTE_USER)
- CLI argument: --user
- Keyword: remote\_user
- Variable: ansible\_user
- Variable: ansible\_ssh\_user

> become: true and remote\_user always go tother?

This would depend on the [become plugin.](https://docs.ansible.com/ansible/latest/plugins/become.html), but at least for the `ansible.builtin` become plugins, none of them use the `remote_user` keyword.

Use `ansible-doc --list -t become` to list become plugins, and `ansible-doc -t ansible.builtin.sudo` to see the options for the specific plugin.

In the case of the `ansible.builtin.sudo` plugin (it is the default), it has the option:

```auto
... snip for brevity ...
- become_user
        User you 'become' to execute the task
        set_via:
          env:
          - name: ANSIBLE_BECOME_USER
          - name: ANSIBLE_SUDO_USER
          ini:
          - key: become_user
            section: privilege_escalation
          - key: user
            section: sudo_become_plugin
          keyword:
          - name: become_user
          vars:
          - name: ansible_become_user
          - name: ansible_sudo_user
        default: root

```

In the order of lowest to highest priority:

- INI entry: `[privilege_escalation] become_user = VALUE`
- INI entry: `[sudo_become_plugin] user = VALUE`
- Environment variable: ANSIBLE\_BECOME\_USER
- Environment variable: ANSIBLE\_SUDO\_USER
- Playbook keyword: become\_user
- Variable: ansible\_become\_user
- Variable: ansible\_sudo\_user
