summaryrefslogtreecommitdiffstats
path: root/ansible/test
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2019-04-26 13:26:45 +0200
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2019-04-26 15:43:11 +0200
commitee157b53be7c176081aed96a74fe8ff09b208cb8 (patch)
tree12af04e01a5753136ce0cff60fd5cedfa009a63a /ansible/test
parentcb94aefb4ef22fdf435578e676823a6b9600cbb9 (diff)
Cleanup Rancher containers after Molecule converge
Rancher role test do remove rancher/agent and rancher/server containers at 'cleanup' stage but Rancher Agent spawned containers are left orphaned. This patch adds tasks to remove them. This patch also adds custom ansible module for listing docker containers (as of ansible 2.7.10 no upstream module provides that feature, even new docker_container_info info module in ansible's devel branch doesn't have it) Change-Id: I6325dc81063b55b70136280273f8f6138c7a0375 Issue-ID: OOM-1811 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'ansible/test')
-rw-r--r--ansible/test/roles/cleanup-rancher/tasks/main.yml18
1 files changed, 18 insertions, 0 deletions
diff --git a/ansible/test/roles/cleanup-rancher/tasks/main.yml b/ansible/test/roles/cleanup-rancher/tasks/main.yml
new file mode 100644
index 00000000..21b02988
--- /dev/null
+++ b/ansible/test/roles/cleanup-rancher/tasks/main.yml
@@ -0,0 +1,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 }}"