aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-08-14 20:23:50 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-08-14 20:58:44 +0200
commit46256a0fb96e095c6012f2bf3dd06c28d1577e64 (patch)
treea70085eb2af0f17686201a754f827b7ccb960e5a
parentdocker: use community.docker.docker_prune (diff)
downloadinfra-ansible-46256a0fb96e095c6012f2bf3dd06c28d1577e64.tar.gz
infra-ansible-46256a0fb96e095c6012f2bf3dd06c28d1577e64.zip
docker: configure logging driver
-rw-r--r--roles/docker/tasks/logging.yml32
-rw-r--r--roles/docker/tasks/main.yml4
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