title: Jenkins docker_login ansible playbook : Permission denied
body: <p>I would like to copy docker container inside docker registry with Jenkins.</p>
  
  <p>When I execute Ansible playbook i get :</p>
  
  <pre><code>"msg": "Error connecting: Error while fetching server API version: ('Connection aborted.', error(13, 'Permission denied'))"
  </code></pre>
  
  <p>I suppose that ansible is run under user jenkins because this <a href="https://stackoverflow.com/questions/43511726/executing-ansible-playbook-using-jenkins">link</a>, and because of the log file:</p>
  
  <pre><code>&lt;127.0.0.1&gt; ESTABLISH LOCAL CONNECTION FOR USER: jenkins
  </code></pre>
  
  <p>Because the ansible playbook try to do a <code>docker_login</code>, I understand that user jenkins need to be able to connect to docker. </p>
  
  <p>So I add jenkins to a docker users : 
  <a href="https://i.stack.imgur.com/UHuJc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UHuJc.png" alt="enter image description here"></a></p>
  
  <p>I don't understand why the permission is denied</p>
  
  <p>The whole log jenkins file:</p>
  
  <pre><code>TASK [Log into Docker registry] 
  ************************************************
  task path: /var/jenkins_home/workspace/.../build_docker.yml:8
  Using module file /usr/lib/python2.7/dist- 
  packages/ansible/modules/core/cloud/docker/docker_login.py
  &lt;127.0.0.1&gt; ESTABLISH LOCAL CONNECTION FOR USER: jenkins
  &lt;127.0.0.1&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1543388409.78-179785864196502 `" &amp;&amp; echo ansible-tmp-1543388409.78-179785864196502="` echo ~/.ansible/tmp/ansible-tmp-1543388409.78-179785864196502 `" ) &amp;&amp; sleep 0'
  &lt;127.0.0.1&gt; PUT /tmp/tmpFASoHo TO /var/jenkins_home/.ansible/tmp/ansible-tmp-1543388409.78-179785864196502/docker_login.py
  &lt;127.0.0.1&gt; EXEC /bin/sh -c 'chmod u+x /var/jenkins_home/.ansible/tmp/ansible-tmp-1543388409.78-179785864196502/ /var/jenkins_home/.ansible/tmp/ansible-tmp-1543388409.78-179785864196502/docker_login.py &amp;&amp; sleep 0'
  &lt;127.0.0.1&gt; EXEC /bin/sh -c '/usr/bin/python /var/jenkins_home/.ansible/tmp/ansible-tmp-1543388409.78-179785864196502/docker_login.py; rm -rf "/var/jenkins_home/.ansible/tmp/ansible-tmp-1543388409.78-179785864196502/" &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'
  fatal: [localhost]: FAILED! =&gt; {
  "changed": false, 
  "failed": true, 
  "invocation": {
      "module_args": {
          "api_version": null, 
          "cacert_path": null, 
          "cert_path": null, 
          "config_path": "~/.docker/config.json", 
          "debug": false, 
          "docker_host": null, 
          "email": null, 
          "filter_logger": false, 
          "key_path": null, 
          "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
          "reauthorize": false, 
          "registry_url": "https://registry.docker....si", 
          "ssl_version": null, 
          "timeout": null, 
          "tls": null, 
          "tls_hostname": null, 
          "tls_verify": null, 
          "username": "jenkins"
      }, 
      "module_name": "docker_login"
  }, 
  "msg": "Error connecting: Error while fetching server API version: ('Connection aborted.', error(13, 'Permission denied'))"
  }
  to retry, use: --limit @/var/jenkins_home/workspace/.../build_docker.retry
  </code></pre>
  
  <p>The whole ansible playbook</p>
  
  <pre><code>---
  - hosts: localhost
    vars:
      git_branch: "{{ GIT_BRANCH|default('development') }}"
    tasks:
    - name: Log into Docker registry
      docker_login:
        registry_url: https://registry.docker.....si
        username: ...
        password: ....
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CghW7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CghW7.png" alt="enter image description here"></a></p>