summaryrefslogtreecommitdiffstats
path: root/playbooks/libvirt/openshift-cluster/terminate.yml
blob: c609169d31f29dd47a849842a09464091b340b2a (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
35
36
37
38
39
40
41
- name: Terminate instance(s)
  hosts: localhost
  connection: local
  gather_facts: no

  vars:
    libvirt_storage_pool_path: "{{ lookup('env','HOME') }}/libvirt-storage-pool-openshift"
    libvirt_storage_pool: 'openshift'
    libvirt_uri: 'qemu:///system'

  tasks:
    - name: List VMs
      virt:
        command: list_vms
      register: list_vms

    - name: Destroy VMs
      virt:
        name: '{{ item[0] }}'
        command: '{{ item[1] }}'
        uri: '{{ libvirt_uri }}'
      with_nested:
        - '{{ list_vms.list_vms }}'
        - [ destroy, undefine ]
      when: item[0]|truncate(cluster_id|length+1, True) == '{{ cluster_id }}-...'

    - name: Delete VMs config drive
      file:
        path: '{{ libvirt_storage_pool_path }}/{{ item }}_configdrive/openstack'
        state: absent
      with_items: '{{ list_vms.list_vms }}'
      when: item|truncate(cluster_id|length+1, True) == '{{ cluster_id }}-...'

    - name: Delete VMs drives
      command: 'virsh -c {{ libvirt_uri }} vol-delete --pool {{ libvirt_storage_pool }} {{ item[0] }}{{ item[1] }}'
      args:
        removes: '{{ libvirt_storage_pool_path }}/{{ item[0] }}{{ item[1] }}'
      with_nested:
        - '{{ list_vms.list_vms }}'
        - [ '_configdrive', '_cloud-init.iso', '.qcow2' ]
      when: item[0]|truncate(cluster_id|length+1, True) == '{{ cluster_id }}-...'