added use-docker-mirror + fixed syslog server func

This commit is contained in:
Ansible Servercow
2024-11-20 17:02:31 +01:00
parent 8a1ca67d67
commit ff56e2861d
2 changed files with 38 additions and 3 deletions

View File

@@ -0,0 +1,35 @@
---
- 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