1 # NB: We use `virsh` here instead of the `virt` module because
2 # these tasks may be called before the dependencies of the `virt`
3 # module are satisfied.
5 - name: Check if libvirt is available
10 register: libvirt_check
12 LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
14 # If libvirt isn't available we can skip everything else.
15 - when: libvirt_check is success
17 LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
23 # Check if the vm nodes exist.
26 virsh domid "{{ item.name }}"
27 with_items: "{{ vm_nodes }}"
31 # Destroy and undefine the vm nodes.
32 - name: Destroy vm vms
34 virsh destroy "{{ item.item.name }}"
36 with_items: "{{ vm_check.results }}"
39 - name: Undefine vm vms
41 virsh undefine "{{ item.item.name }}"
43 with_items: "{{ vm_check.results }}"
45 # The `virsh vol-dumpxml ... > /dev/null` is here (and elsewhere) due to
48 # [1293804]: https://bugzilla.redhat.com/show_bug.cgi?id=1293804
49 - name: Delete baremetal vm storage
51 virsh vol-dumpxml --pool '{{ libvirt_volume_pool }}' \
52 '{{ item.name }}'.qcow2 2>&1 > /dev/null
53 virsh vol-delete --pool '{{ libvirt_volume_pool }}' \
54 '{{ item.name }}'.qcow2
55 with_items: "{{ vm_nodes }}"
58 - name: Check volume pool
60 virsh pool-uuid "{{ libvirt_volume_pool }}"
64 # See https://www.redhat.com/archives/libvirt-users/2016-March/msg00123.html
65 # TL;DR: ensure that the pool really exists if the previous
67 - name: Work around libvirt bug
69 virsh pool-dumpxml "{{ libvirt_volume_pool }}" |
70 virsh pool-define /dev/stdin
71 when: pool_check is success
73 - name: Destroy volume pool
75 virsh pool-destroy "{{ libvirt_volume_pool }}"
76 when: pool_check is success
79 - name: Undefine volume pool
81 virsh pool-undefine "{{ libvirt_volume_pool }}"
82 when: pool_check is success
84 - name: Get UID of pool user
85 command: id -u "{{ ansible_user_id }}"
88 when: pool_check is success
90 - name: Destroy pool definition file
92 path: "/run/user/{{ pool_uid.stdout }}/libvirt/storage/run/{{ libvirt_volume_pool }}.xml"
94 when: pool_check is success