Add option to force-recreate containers on config change

This commit is contained in:
Tobias Reisinger 2023-12-11 02:40:11 +01:00
parent 570864c00f
commit c32e305eb3
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
3 changed files with 10 additions and 2 deletions

View file

@ -12,5 +12,12 @@
src: telegraf.conf.j2 src: telegraf.conf.j2
dest: "{{ (service_path, 'telegraf.conf') | path_join }}" dest: "{{ (service_path, 'telegraf.conf') | path_join }}"
mode: "0664" 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 - import_tasks: steps/start-service.yml

View file

@ -1,6 +1,7 @@
- name: Setting the service path - name: Set common facts
ansible.builtin.set_fact: ansible.builtin.set_fact:
service_path: "{{ (services_path, svc.name) | path_join }}" service_path: "{{ (services_path, svc.name) | path_join }}"
docker_force_recreate: ""
- name: Create a service directory - name: Create a service directory
ansible.builtin.file: ansible.builtin.file:

View file

@ -22,7 +22,7 @@
- name: Start service - name: Start service
ansible.builtin.command: ansible.builtin.command:
cmd: docker compose up -d cmd: docker compose up -d {{ docker_force_recreate }}
chdir: "{{ service_path }}" chdir: "{{ service_path }}"
when: "'local-dev' != inventory_hostname" when: "'local-dev' != inventory_hostname"
register: cmd_result register: cmd_result