1
0
IaC/ansible/roles/vm_destroy/tasks/destroy.yaml

58 lines
1.4 KiB
YAML
Raw Normal View History

---
- 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
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: delete the firmware vars file
ansible.builtin.file:
path: "{{ firmware_vhd_pool_dir }}/{{ vm_name }}_VARS.fd"
state: absent
2022-10-30 07:02:50 -04:00
- 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"