| --- |
| # Remove containers spawned by Rancher Agent |
| - name: Get list of containers spawned by Rancher Agent |
| docker_list_containers: |
| label_name: "{{ item.label }}" |
| label_value: "{{ item.value }}" |
| loop: "{{ container_list_by_label }}" |
| register: docker_list_containers_var |
| |
| - name: set fact # save a list of containers found by previous task to orphaned_containers var |
| set_fact: orphaned_containers="{{ orphaned_containers|default([]) + item.containers }}" |
| loop: "{{ docker_list_containers_var.results }}" |
| |
| - name: Remove orphaned containers |
| docker_container: |
| name: "{{ item }}" |
| state: absent |
| loop: "{{ orphaned_containers }}" |