Search code examples
dockeransibledocker-registry

Ansible doesn't add credentials to ~/.docker/config.json despite succesful login to registry


I can't login to private docker login registry via ansible. The login itself is succesful, which I can see in registry container logs; besides ansible doesn't throw erorrs when doing login task. However after running ansible role, I can't pull images. Apparently ansible never adds any credentials to docker's config file. When I login manually from host machine, everything works fine.

Does anyone know what's the problem?

versions: Ansible 2.3.2.0, Docker 17.12

ansible role in main.yml:

---
 # should work but does not - ansible doesn't add credentials to ~/.docker.config.json... have to log manually  
- name: login to private registry
  docker_login:
    registry: "{{ registry_container_url }}"
    username: "{{ registry_user }}"
    password: "{{ registry_password }}"
    reauthorize: yes

playbook only executes this role:

---
- hosts: host1
  become: yes
  roles:
    - testrole

Log:

ok: [node02]

TASK [docker-test : login to private registry] *************************************************************************
changed: [node02]

PLAY RECAP ************************************************************************************************************
node02                     : ok=2    changed=1    unreachable=0    failed=0   

Solution

  • Ok, I got it.

    become has to be set to no in the playbook.