infrastructure/playbooks/tasks/stop-unused.yml

24 lines
725 B
YAML
Raw Normal View History

2024-10-13 21:20:11 +00:00
- name: Get running compose projects
ansible.builtin.shell:
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 }}"