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