summaryrefslogtreecommitdiffstats
path: root/ansible/roles/rke/molecule/default/destroy.yml
blob: 591da82eee7576ef547550d80548d9fe78d5e825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
---
- name: Destroy
  hosts: localhost
  connection: local
  gather_facts: false
  no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
  tasks:
    - name: Destroy molecule instance(s)
      docker_container:
        name: "{{ item.name }}"
        docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
        state: absent
        force_kill: "{{ item.force_kill | default(true) }}"
        # Modification: we want to clean up old volumes.
        keep_volumes: false
      register: server
      with_items: "{{ molecule_yml.platforms }}"
      async: 7200
      poll: 0

    - name: Wait for instance(s) deletion to complete
      async_status:
        jid: "{{ item.ansible_job_id }}"
      register: docker_jobs
      until: docker_jobs.finished
      retries: 300
      with_items: "{{ server.results }}"

    - name: Delete docker network(s)
      docker_network:
        name: "{{ item }}"
        docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
        state: absent
      with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}"