feat(docker): Add docker stack cleaning role

Runs before setting up any new stacks or pursue other modifications to
docker deployments.

Brings down any stack which is not currently defined in a role. This
makes the whole installation more idempotent since we take care to not
only bring _up_ any necessary docker containers, but also bring _down_
those that have become unnecessary.
This commit is contained in:
Marty Oehme 2025-03-19 10:49:58 +01:00
parent 4671801a84
commit 814f1e008f
Signed by: Marty
GPG key ID: 4E535BC19C61886E
2 changed files with 18 additions and 0 deletions

View file

@ -0,0 +1,12 @@
---
- name: Get running docker stacks
community.docker.docker_stack_info:
register: running_stacks
become: true
- name: Remove stacks without matching role
community.docker.docker_stack:
name: "{{ item.Name }}"
state: "absent"
loop: "{{ running_stacks.results | rejectattr('Name', 'in', role_names) }}"
become: true