53 lines
1.3 KiB
YAML
53 lines
1.3 KiB
YAML
---
|
|
- name: set vm_name
|
|
ansible.builtin.set_fact:
|
|
vm_name: "{{ vm_name_prefix }}{{ vm_number }}"
|
|
|
|
- name: debug vm_name
|
|
ansible.builtin.debug:
|
|
msg:
|
|
- "VM name is {{ vm_name }}"
|
|
|
|
- name: list vms
|
|
community.libvirt.virt:
|
|
command: list_vms
|
|
register: vm_list
|
|
|
|
- name: debug vm list
|
|
ansible.builtin.debug:
|
|
var: vm_list.list_vms
|
|
|
|
- name: proceed if vm exists
|
|
when: vm_name in vm_list.list_vms
|
|
block:
|
|
|
|
- name: shutdown the vm
|
|
community.libvirt.virt:
|
|
state: shutdown
|
|
name: "{{ vm_name }}"
|
|
|
|
- name: delete the firmware vars file
|
|
ansible.builtin.file:
|
|
path: "{{ firmware_vhd_pool_dir }}/{{ vm_name }}_VARS.fd"
|
|
state: absent
|
|
|
|
- name: undefine (delete) the vm
|
|
community.libvirt.virt:
|
|
command: undefine
|
|
name: "{{ vm_name }}"
|
|
|
|
- name: delete the root vhd
|
|
when: delete_root_vhd
|
|
ansible.builtin.file:
|
|
path: "{{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2"
|
|
state: absent
|
|
|
|
- name: delete the data vhds
|
|
when: delete_data_vhd
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: absent
|
|
with_items:
|
|
- "{{ containers_vhd_pool_dir }}/{{ vm_name }}_vdb.qcow2"
|
|
- "{{ data_nvme_vhd_pool_dir }}/{{ vm_name }}_vdc.qcow2"
|
|
- "{{ data_hdd_vhd_pool_dir }}/{{ vm_name }}_vdd.qcow2" |