35 lines
1.3 KiB
YAML
35 lines
1.3 KiB
YAML
---
|
|
- name: Update Docker Daemon configuration to use Docker Mirror
|
|
hosts: all
|
|
become: yes
|
|
tasks:
|
|
- name: Read current Docker daemon.json
|
|
ansible.builtin.slurp:
|
|
src: /etc/docker/daemon.json
|
|
register: current_daemon_json
|
|
|
|
- name: Parse current Docker daemon.json
|
|
set_fact:
|
|
current_daemon_config: "{{ current_daemon_json['content'] | b64decode | from_json }}"
|
|
|
|
- name: Check current registry-mirrors setting
|
|
set_fact:
|
|
registry_mirrors_current: "{{ current_daemon_config['registry-mirrors'] | default('not_set') }}"
|
|
|
|
- name: Update Docker daemon.json with registry-mirrors configuration if registry-mirrors not set or not equals
|
|
ansible.builtin.copy:
|
|
dest: /etc/docker/daemon.json
|
|
content: "{{ updated_daemon_json | to_nice_json }}"
|
|
vars:
|
|
registry_config: {
|
|
"registry-mirrors": ["https://dim.servercow.com"]
|
|
}
|
|
updated_daemon_json: "{{ current_daemon_config | combine(registry_config) }}"
|
|
when: registry_mirrors_current != 'https://dim.servercow.com' or log is undefined
|
|
register: daemon_update
|
|
|
|
- name: Restart Docker to apply changes
|
|
ansible.builtin.systemd:
|
|
name: docker
|
|
state: restarted
|
|
when: daemon_update.changed |