mirror of
https://github.com/geerlingguy/ansible-role-docker.git
synced 2025-08-20 13:46:32 +02:00
Adding option to login to private docker registries
This commit is contained in:
parent
26297760a3
commit
f20ceef3d6
@ -59,6 +59,13 @@ Usually in combination with changing `docker_yum_repository` as well.
|
|||||||
- user2
|
- user2
|
||||||
|
|
||||||
A list of system users to be added to the `docker` group (so they can use Docker on the server).
|
A list of system users to be added to the `docker` group (so they can use Docker on the server).
|
||||||
|
|
||||||
|
docker_logins:
|
||||||
|
- url: repository.example.com
|
||||||
|
username: myuser
|
||||||
|
password: mypass
|
||||||
|
|
||||||
|
A list of private container registries to be logged in with `docker`.
|
||||||
|
|
||||||
## Use with Ansible (and `docker` Python library)
|
## Use with Ansible (and `docker` Python library)
|
||||||
|
|
||||||
|
@ -29,3 +29,6 @@ docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg
|
|||||||
|
|
||||||
# A list of users who will be added to the docker group.
|
# A list of users who will be added to the docker group.
|
||||||
docker_users: []
|
docker_users: []
|
||||||
|
|
||||||
|
# A list of private repositories and login credentials
|
||||||
|
docker_logins: []
|
||||||
|
10
tasks/docker-login.yml
Normal file
10
tasks/docker-login.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
- name: Check if credentials exist and are authorized
|
||||||
|
command: timeout 5 docker login {{ docker_login.url }}
|
||||||
|
register: docker_login_check
|
||||||
|
changed_when: false
|
||||||
|
failed_when: docker_login_check.rc not in (0, 124) # 124 is timeout exceeded code
|
||||||
|
|
||||||
|
- name: Login to registry {{ docker_login.url }} as {{ docker_login.username }}
|
||||||
|
shell: docker login --username {{ docker_login.username }} --password {{ docker_login.password }} {{ docker_login.url }} 2>/dev/null
|
||||||
|
when: docker_login_check.rc == 124
|
@ -25,3 +25,10 @@
|
|||||||
|
|
||||||
- include_tasks: docker-users.yml
|
- include_tasks: docker-users.yml
|
||||||
when: docker_users | length > 0
|
when: docker_users | length > 0
|
||||||
|
|
||||||
|
- include_tasks: docker-login.yml
|
||||||
|
loop: "{{ docker_logins }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: docker_login
|
||||||
|
when: docker_logins | length > 0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user