infrastructure/playbooks/tasks/stop-unused.yml
Tobias Reisinger 4104057771
Fix pre-commit hooks and move directories
roles/ and inventory/ are now in playbooks/
also fixed issues reported by ansible-lint
2024-10-14 18:31:36 +02:00

23 lines
725 B
YAML

- 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
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 }}"