Add task to stop unused services
This commit is contained in:
parent
dbb3075c82
commit
e68f2f2cec
2 changed files with 28 additions and 0 deletions
|
@ -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
|
||||||
|
|
17
playbooks/tasks/stop-unused.yml
Normal file
17
playbooks/tasks/stop-unused.yml
Normal 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 }}"
|
||||||
|
|
Loading…
Reference in a new issue