Add task to stop unused services

This commit is contained in:
Tobias Reisinger 2024-10-13 23:20:11 +02:00
parent dbb3075c82
commit e68f2f2cec
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 28 additions and 0 deletions

View file

@ -30,3 +30,14 @@
tags: tags:
- caddy - caddy
- never - never
- name: Stop unused services
ansible.builtin.include_tasks:
file: tasks/stop-unused.yml
apply:
tags:
- cleanup
- always
tags:
- cleanup
- always

View file

@ -0,0 +1,17 @@
- name: Get running compose projects
ansible.builtin.shell:
cmd: 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 }}"