add vm_destroy playbook and role

correct network addressing in template
write hostname to /etc/hostname
This commit is contained in:
2022-10-30 23:48:43 +13:00
parent 73c9106c8f
commit 50c451e94d
7 changed files with 113 additions and 1 deletions

View File

@ -0,0 +1,48 @@
---
- 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: stop the vm
community.libvirt.virt:
state: shutdown
name: "{{ vm_name }}"
- name: destroy the vm
community.libvirt.virt:
state: destroyed
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"

View File

@ -0,0 +1,6 @@
---
- name: create k8s vms
with_items: "{{ vm_name_suffixes }}"
loop_control:
loop_var: vm_number
ansible.builtin.include_tasks: destroy.yaml