简体   繁体   中英

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   

Ok, I got it.

become has to be set to no in the playbook.

You could also add the docker config to Root's home if you need to run as privileged. IE:

/home/root/.docker/config.json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM