docker_compose(role): use community.docker.docker_compose_v2 module

Use the community.docker.docker_compose_v2 module as it supports proper
changed handling out of the box, making the roles code more
straightforward and work. Also just do a docker compose restart instead
of having the custom docker compose reload script.

https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_v2_module.html
This commit is contained in:
June 2025-11-02 23:13:20 +01:00
commit ae60d6fea6
Signed by: june
SSH key fingerprint: SHA256:o9EAq4Y9N9K0pBQeBTqhSDrND5E7oB+60ZNx0U1yPe0
5 changed files with 21 additions and 48 deletions

View file

@ -1,13 +1,11 @@
- name: docker compose down
ansible.builtin.command:
cmd: /usr/bin/docker compose down
chdir: /ansible_docker_compose
community.docker.docker_compose_v2:
project_src: /ansible_docker_compose
state: absent
become: true
changed_when: true # This is always changed.
- name: docker compose reload script
ansible.builtin.command:
cmd: /usr/bin/docker compose {{ docker_compose__restart_cmd }}
chdir: /ansible_docker_compose
- name: docker compose restart
community.docker.docker_compose_v2:
project_src: /ansible_docker_compose
state: restarted
become: true
changed_when: true # Mark this as always changed (for now?).
when: docker_compose__restart_cmd != ""