Bartek Grzybowski | ee157b5 | 2019-04-26 13:26:45 +0200 | [diff] [blame] | 1 | --- |
| 2 | # Remove containers spawned by Rancher Agent |
| 3 | - name: Get list of containers spawned by Rancher Agent |
| 4 | docker_list_containers: |
| 5 | label_name: "{{ item.label }}" |
| 6 | label_value: "{{ item.value }}" |
| 7 | loop: "{{ container_list_by_label }}" |
| 8 | register: docker_list_containers_var |
| 9 | |
| 10 | - name: set fact # save a list of containers found by previous task to orphaned_containers var |
| 11 | set_fact: orphaned_containers="{{ orphaned_containers|default([]) + item.containers }}" |
| 12 | loop: "{{ docker_list_containers_var.results }}" |
| 13 | |
| 14 | - name: Remove orphaned containers |
| 15 | docker_container: |
| 16 | name: "{{ item }}" |
| 17 | state: absent |
| 18 | loop: "{{ orphaned_containers }}" |