summaryrefslogtreecommitdiffstats
path: root/ansible/test/roles/cleanup-rancher/tasks/main.yml
blob: 21b0298881cd10f34d9bfc13d12e3804c535fcd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
---
# 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 }}"