From 46256a0fb96e095c6012f2bf3dd06c28d1577e64 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 14 Aug 2023 20:23:50 +0200 Subject: docker: configure logging driver --- roles/docker/tasks/logging.yml | 32 ++++++++++++++++++++++++++++++++ roles/docker/tasks/main.yml | 4 ++++ 2 files changed, 36 insertions(+) create mode 100644 roles/docker/tasks/logging.yml 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 -- cgit v1.2.3