title: Ansible: ansible_user in inventory vs remote_user in playbook
body: <p>I am trying to run an Ansible playbook against a server using an account other than the one I am logged on the control machine. I tried to specify an <code>ansible_user</code> in the inventory file according to the documentation on <a href="http://docs.ansible.com/ansible/intro_inventory.html" rel="noreferrer">Inventory</a>:</p>
  
  <pre><code>[srv1]
  192.168.1.146 ansible_connection=ssh ansible_user=user1
  </code></pre>
  
  <p>However Ansible called with <code>ansible-playbook -i inventory playbook.yml -vvvv</code> prints the following:</p>
  
  <pre><code>GATHERING FACTS ***************************************************************
  &lt;192.168.1.146&gt; ESTABLISH CONNECTION FOR USER: techraf
  </code></pre>
  
  <p>What worked for me was adding the <code>remote_user</code> argument to the playbook:</p>
  
  <pre><code>- hosts: srv1
    remote_user: user1
  </code></pre>
  
  <p>Now the same Ansible command connects as <code>user1</code>:</p>
  
  <pre><code>GATHERING FACTS ***************************************************************
  &lt;192.168.1.146&gt; ESTABLISH CONNECTION FOR USER: user1
  </code></pre>
  
  <p>Also adding <code>remote_user</code> variable to <code>ansible.cfg</code> makes Ansible use the intended user instead of the logged-on one.</p>
  
  <p>Are the <code>ansible_user</code> in inventory file and <code>remote_user</code> in playbook/<code>ansible.cfg</code> for different purposes? </p>
  
  <p>What is the <code>ansible_user</code> used for? Or why doesn't Ansible observe the setting in the inventory?</p>