From c85fdf12b53f1080855868238847ffc3be0f9f97 Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Sun, 25 Dec 2022 17:55:40 +0100 Subject: [PATCH] Restart Docker daemon if config changed --- roles/docker/defaults/main.yml | 1 + roles/docker/tasks/main.yml | 8 +------- roles/docker/tasks/services.yml | 12 ++++++++++-- roles/os_config/defaults/main.yml | 1 + roles/os_config/tasks/main.yml | 1 + 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml index 37b128e..5f5a552 100644 --- a/roles/docker/defaults/main.yml +++ b/roles/docker/defaults/main.yml @@ -1,3 +1,4 @@ +# vim: ft=yaml.ansible --- base_domain: sapti.me base_volume: "{{ hdd_mount_point }}/apps" diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 60fef27..3e2cf83 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -1,3 +1,4 @@ +# vim: ft=yaml.ansible --- - name: Add Docker PGP key apt_key: @@ -36,13 +37,6 @@ - docker - docker-compose -- name: Copy Docker daemon config file - template: - src: daemon.json.j2 - dest: /etc/docker/daemon.json - owner: root - mode: u=rw,g=r,o=r - - name: Set up Docker services import_tasks: services.yml tags: diff --git a/roles/docker/tasks/services.yml b/roles/docker/tasks/services.yml index 16d8791..bf62699 100644 --- a/roles/docker/tasks/services.yml +++ b/roles/docker/tasks/services.yml @@ -1,10 +1,18 @@ # vim: ft=yaml.ansible --- -- name: Start but disable Docker daemon +- name: Copy Docker daemon config file + template: + src: daemon.json.j2 + dest: /etc/docker/daemon.json + owner: root + mode: u=rw,g=r,o=r + register: daemon_config + +- name: (Disable and) start Docker daemon service: name: "{{ item }}" enabled: false - state: started + state: "{{ 'restarted' if daemon_config.changed else 'started' }}" loop: - docker.socket - docker.service diff --git a/roles/os_config/defaults/main.yml b/roles/os_config/defaults/main.yml index 141f8ae..4e6a8d4 100644 --- a/roles/os_config/defaults/main.yml +++ b/roles/os_config/defaults/main.yml @@ -1,2 +1,3 @@ +# vim: ft=yaml.ansible --- ssh_key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPd/4fQV7CL8/KVwbo/phiV5UdXFBIDlkZ+ps8C7FeRf diff --git a/roles/os_config/tasks/main.yml b/roles/os_config/tasks/main.yml index 3497d2a..3d824f1 100644 --- a/roles/os_config/tasks/main.yml +++ b/roles/os_config/tasks/main.yml @@ -1,3 +1,4 @@ +# vim: ft=yaml.ansible --- - name: Configure system packages import_tasks: pkgs.yml