Debian Codegraph @

ansible_collections/community/libvirt/tests/integration/targets/virt_undefine/tasks/main.yml

raw
1 ---
2 - name: Create VM XML definition
3 template:
4 src: files/vm_template.xml.j2
5 dest: "/tmp/{{ vm_name }}.xml"
6
7 - name: Define VM
8 community.libvirt.virt:
9 command: define
10 xml: "{{ lookup('file', '/tmp/' + vm_name + '.xml') }}"
11 uri: qemu:///system
12
13 - name: Create the disk image file for base image
14 ansible.builtin.command: "qemu-img create -f qcow2 {{ libvirt_disk_path }}/{{ vm_name }}_copy.qcow2 {{ libvirt_disk_size }}G"
15
16 - name: Copy the base image for another vm
17 ansible.builtin.command: "qemu-img create -f qcow2 -F qcow2 -b {{ libvirt_disk_path }}/{{ vm_name }}_copy.qcow2 {{ libvirt_disk_path }}/{{ vm_name }}.qcow2"
18
19 - name: Validate the VM
20 community.libvirt.virt:
21 command: list_vms
22 register: vm_list
23
24 - name: Show VMs
25 debug:
26 var: vm_list
27
28 - name: Check if file exists
29 stat:
30 path: "{{ libvirt_disk_path }}/{{ vm_name }}.qcow2"
31 register: file_status
32
33 - name: Assert file exists
34 assert:
35 that:
36 - file_status.stat.exists
37 fail_msg: "QCOW file does not exist"
38 success_msg: "File exists as expected"
39
40
41 - name: Refresh the storage pool
42 community.libvirt.virt_pool:
43 command: refresh
44 name: "{{ libvirt_pool_name }}"
45
46 - name: Destroy VMs
47 community.libvirt.virt:
48 state: destroyed
49 name: "{{ vm_name }}"
50
51 - name: remove and undefine vm
52 community.libvirt.virt:
53 command: undefine
54 name: "{{ vm_name }}"
55 flags: managed_save,snapshots_metadata,delete_volumes
56
57 - name: Check if file exists
58 stat:
59 path: "{{ libvirt_disk_path }}/{{ vm_name }}.qcow2"
60 register: file_status
61
62 - name: Assert file does not exist
63 assert:
64 that:
65 - not file_status.stat.exists
66 success_msg: "QCOW file does not exist"
67 fail_msg: "File exists... failed to remove"
68
69 - name: Check if base image still exists
70 stat:
71 path: "{{ libvirt_disk_path }}/{{ vm_name }}_copy.qcow2"
72 register: base_image
73
74 - name: Assert base image still exists
75 assert:
76 that:
77 - base_image.stat.exists
78 success_msg: "BASE QCOW file still exists"
79 fail_msg: "Base Image Missing."