title: Using ansible delegate_to with docker: permission denied
body: <p>I would like to execute a command inside a container of a machine I manage with ansible.</p>
  
  <p>This is possible with the <code>delegate_to</code> command (see <a href="https://stackoverflow.com/a/41626257/458274">https://stackoverflow.com/a/41626257/458274</a>):</p>
  
  <pre><code>- name: Add container to inventory
    add_host:
      name: mycontainer
      ansible_connection: docker
    changed_when: false
  
  - name: Do something in container
    delegate_to: mycontainer
    raw: echo "hello world"
  </code></pre>
  
  <p>However, the user I'm using has no permission to access <code>/var/run/docker.sock</code>. I could fix this by adding the user to the <code>docker</code> group, but I feel that this is a bad security practice, since any program running with this user account could now gain root permission without a password.</p>
  
  <p>Using <code>become</code> does not work either, since it will be delegated to the container, too.</p>
  
  <p>How can I use <code>delegate_to</code>, but switch to another user first?</p>