2022-10-30 06:48:43 -04:00
|
|
|
---
|
|
|
|
- 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:
|
|
|
|
|
2022-10-30 06:57:26 -04:00
|
|
|
- name: shutdown the vm
|
2022-10-30 06:48:43 -04:00
|
|
|
community.libvirt.virt:
|
|
|
|
state: shutdown
|
|
|
|
name: "{{ vm_name }}"
|
|
|
|
|
2022-10-30 06:57:26 -04:00
|
|
|
# - name: destroy the vm
|
|
|
|
# community.libvirt.virt:
|
|
|
|
# state: destroyed
|
|
|
|
# name: "{{ vm_name }}"
|
|
|
|
|
|
|
|
- name: undefine the vm
|
2022-10-30 06:48:43 -04:00
|
|
|
community.libvirt.virt:
|
2022-10-30 06:58:47 -04:00
|
|
|
command: undefine
|
2022-10-30 06:48:43 -04:00
|
|
|
name: "{{ vm_name }}"
|
|
|
|
|
2022-10-30 06:57:26 -04:00
|
|
|
- name: delete the firmware vars file
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ firmware_vhd_pool_dir }}/{{ vm_name }}_VARS.fd"
|
|
|
|
state: absent
|
|
|
|
|
2022-10-30 06:48:43 -04:00
|
|
|
- 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"
|