title: Ansible through docker, docker host in the inventory
body: <p>Using <a href="https://hub.docker.com/r/williamyeh/ansible/" rel="nofollow noreferrer">this docker image</a> from Docker Hub, I'm trying to run an ansible playbook that would configure the machine on which the container is running.</p>
  
  <p>As an example, I run this:</p>
  
  <pre><code>docker run --net="host" -v &lt;path_inventory&gt;:/inventory -v &lt;path_playbook&gt;:/playbook.yml williamyeh/ansible:ubuntu16.04 ansible-playbook -vvvv -i /inventory /playbook.yml
  </code></pre>
  
  <p>With this options, I can ping localhost and the inventory and playbook are both accessible.</p>
  
  <p>The inventory is configured to use a local connection:</p>
  
  <pre><code>[executors]
  127.0.0.1
  
  [executors:vars]
  ansible_connection=local
  ansible_user=&lt;my_user_in_docker_host&gt;
  ansible_become=True
  </code></pre>
  
  <p>The group <em>executors</em> is the one referenced from the playbook.</p>
  
  <p>I see that the playbook is trying to connect as root (what I get by default when I attach to the container). Specifying <em>-u</em> when running the container doesn't seem to get along with Ansible.</p>
  
  <blockquote>
    <p>&lt;127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root</p>
  </blockquote>
  
  <p>... followed by errors complaining about any command not available, after a successful local connection. That is what makes no sense for me given that both root or non-root users can execute them.</p>
  
  <p>Any idea?</p>