Use new docker compose module and force restart if copy changed

This commit is contained in:
SebClem 2024-04-20 13:40:35 +02:00
parent e1d46ee244
commit 4735876db2
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50

View File

@ -25,6 +25,7 @@
dest: "{{ docker_compose_remote_project_dir }}" dest: "{{ docker_compose_remote_project_dir }}"
mode: "preserve" mode: "preserve"
directory_mode: "711" directory_mode: "711"
register: copy_result
loop: "{{ docker_compose_project_list }}" loop: "{{ docker_compose_project_list }}"
- name: Create external docker networks - name: Create external docker networks
@ -34,23 +35,16 @@
loop: "{{ docker_compose_external_network }}" loop: "{{ docker_compose_external_network }}"
when: docker_compose_external_network is defined 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 - name: Manage docker compose project
ansible.builtin.shell: community.docker.docker_compose_v2:
chdir: "{{ docker_compose_remote_project_dir + '/' + item.name }}" project_src: "{{ docker_compose_remote_project_dir + '/' + item.item.name }}"
cmd: "docker compose pull && docker compose {{ 'restart' if docker_compose_state == 'restarted' else 'up -d' }} " remove_orphans: true
loop: "{{ docker_compose_project_list }}" pull: always
register: docker_compose_out build: always
changed_when: "'Started' in docker_compose_out.stderr" state: "{{ 'restarted' if item.changed else docker_compose_state }}"
loop: "{{ copy_result.results }}"
when: not item.failed
- name: Prune docker - name: Prune docker
community.docker.docker_prune: community.docker.docker_prune: