From c32e305eb32aedfecd41abcfbccb9a4404f4d1d5 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Mon, 11 Dec 2023 02:40:11 +0100 Subject: [PATCH] Add option to force-recreate containers on config change --- _ansible/roles/telegraf/tasks/main.yml | 7 +++++++ _ansible/tasks/steps/create-service-directory.yml | 3 ++- _ansible/tasks/steps/start-service.yml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/_ansible/roles/telegraf/tasks/main.yml b/_ansible/roles/telegraf/tasks/main.yml index c7bea0f..88cf4d3 100644 --- a/_ansible/roles/telegraf/tasks/main.yml +++ b/_ansible/roles/telegraf/tasks/main.yml @@ -12,5 +12,12 @@ src: telegraf.conf.j2 dest: "{{ (service_path, 'telegraf.conf') | path_join }}" mode: "0664" + register: cmd_result + + + - name: Set the docker force-recreate flag + ansible.builtin.set_fact: + docker_force_recreate: "--force-recreate" + when: cmd_result.changed - import_tasks: steps/start-service.yml diff --git a/_ansible/tasks/steps/create-service-directory.yml b/_ansible/tasks/steps/create-service-directory.yml index 663bdff..7f29a70 100644 --- a/_ansible/tasks/steps/create-service-directory.yml +++ b/_ansible/tasks/steps/create-service-directory.yml @@ -1,6 +1,7 @@ -- name: Setting the service path +- name: Set common facts ansible.builtin.set_fact: service_path: "{{ (services_path, svc.name) | path_join }}" + docker_force_recreate: "" - name: Create a service directory ansible.builtin.file: diff --git a/_ansible/tasks/steps/start-service.yml b/_ansible/tasks/steps/start-service.yml index a88d14d..9b334c3 100644 --- a/_ansible/tasks/steps/start-service.yml +++ b/_ansible/tasks/steps/start-service.yml @@ -22,7 +22,7 @@ - name: Start service ansible.builtin.command: - cmd: docker compose up -d + cmd: docker compose up -d {{ docker_force_recreate }} chdir: "{{ service_path }}" when: "'local-dev' != inventory_hostname" register: cmd_result