From 4735876db29b2ce6b9ddfb5c6e8d2c2408a59d4c Mon Sep 17 00:00:00 2001 From: SebClem Date: Sat, 20 Apr 2024 13:40:35 +0200 Subject: [PATCH] Use new docker compose module and force restart if copy changed --- roles/docker_compose/tasks/main.yml | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/roles/docker_compose/tasks/main.yml b/roles/docker_compose/tasks/main.yml index 65f30b7..6cc72f2 100644 --- a/roles/docker_compose/tasks/main.yml +++ b/roles/docker_compose/tasks/main.yml @@ -25,6 +25,7 @@ dest: "{{ docker_compose_remote_project_dir }}" mode: "preserve" directory_mode: "711" + register: copy_result loop: "{{ docker_compose_project_list }}" - name: Create external docker networks @@ -34,23 +35,16 @@ loop: "{{ docker_compose_external_network }}" when: docker_compose_external_network is defined -# Compose V2 Not supported -# - name: Manage docker compose project -# community.docker.docker_compose: -# project_src: "{{ remote_project_dir + '/' + item.name }}" -# remove_orphans: true -# pull: true -# build: true -# state: "{{ docker_compose_state }}" -# loop: "{{ docker_compose_project_list }}" - - name: Manage docker compose project - ansible.builtin.shell: - chdir: "{{ docker_compose_remote_project_dir + '/' + item.name }}" - cmd: "docker compose pull && docker compose {{ 'restart' if docker_compose_state == 'restarted' else 'up -d' }} " - loop: "{{ docker_compose_project_list }}" - register: docker_compose_out - changed_when: "'Started' in docker_compose_out.stderr" + community.docker.docker_compose_v2: + project_src: "{{ docker_compose_remote_project_dir + '/' + item.item.name }}" + remove_orphans: true + pull: always + build: always + state: "{{ 'restarted' if item.changed else docker_compose_state }}" + loop: "{{ copy_result.results }}" + when: not item.failed + - name: Prune docker community.docker.docker_prune: