2024-10-13 21:20:11 +00:00
|
|
|
- name: Get running compose projects
|
|
|
|
ansible.builtin.shell:
|
2024-10-14 16:30:24 +00:00
|
|
|
cmd: |
|
|
|
|
set -o pipefail
|
|
|
|
docker container ls --format json \
|
|
|
|
| jq .Labels \
|
|
|
|
| grep -oe 'com.docker.compose.project=[a-zA-Z0-9_-]*' \
|
|
|
|
| sed -e 's/com.docker.compose.project=//' \
|
|
|
|
| sort \
|
|
|
|
| uniq
|
2024-10-13 21:20:11 +00:00
|
|
|
changed_when: false
|
|
|
|
register: docker_compose_projects_result
|
|
|
|
|
|
|
|
- name: Get unused services
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
unused_services: "{{ docker_compose_projects_result.stdout_lines | difference(host_services) }}"
|
|
|
|
|
|
|
|
- name: Stop unused services
|
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: docker compose down
|
|
|
|
chdir: "{{ (services_path, item) | path_join }}"
|
|
|
|
changed_when: true
|
|
|
|
loop: "{{ unused_services }}"
|