diff options
Diffstat (limited to '')
-rw-r--r-- | roles/docker/tasks/logging.yml | 32 | ||||
-rw-r--r-- | roles/docker/tasks/main.yml | 4 |
2 files changed, 36 insertions, 0 deletions
diff --git a/roles/docker/tasks/logging.yml b/roles/docker/tasks/logging.yml new file mode 100644 index 0000000..99d3cab --- /dev/null +++ b/roles/docker/tasks/logging.yml @@ -0,0 +1,32 @@ +- name: Read Docker config + block: + - name: Read daemon.json + become: true + ansible.builtin.slurp: + src: /etc/docker/daemon.json + register: docker_config + + - name: Parse daemon.json + ansible.builtin.set_fact: + docker_config: '{{ docker_config.content | b64decode | from_json }}' + rescue: + - name: daemon.json is missing + ansible.builtin.set_fact: + docker_config: {} + +- name: Modify Docker config + become: true + ansible.builtin.copy: + dest: /etc/docker/daemon.json + content: '{{ docker_config | combine({"log-driver": docker_logging_driver}) | to_nice_json }}' + owner: root + group: root + mode: '644' + register: daemon_json + +- name: Restart Docker + become: true + ansible.builtin.systemd_service: + name: docker + state: restarted + when: daemon_json.changed diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index ae8f668..c8361a0 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -17,3 +17,7 @@ networks: true volumes: true builder_cache: true + +- name: Configure Docker logging driver + when: docker_logging_driver is defined and docker_logging_driver + ansible.builtin.include_tasks: logging.yml |