Files
fedora-infra_ansible/playbooks/destroy_virt_inst.yml
Nils Philippsen 6c85fda0c9 Mass remove/replace iad2 -> rdu3, 10.3. -> 10.16.
Signed-off-by: Nils Philippsen <nils@redhat.com>
2025-07-03 20:05:02 +02:00

47 lines
1.3 KiB
YAML

# only works with -e target=
# read configs from host_vars
# check for host already existing
# if it exists
# kill it
# lvremove disk?
# if not
# exit with failure
# requires --extra-vars="target=hostspec"
---
- name: Destroy and undefine vm
hosts: "{{ target }}"
user: root
gather_facts: false
tasks:
- name: Get vm list on the vmhost
delegate_to: "{{ vmhost }}"
virt: command=list_vms
register: result
- name: Fail if the host is not already defined/existent
local_action: fail msg="host does not exist on {{ vmhost }}"
when: inventory_hostname not in result.list_vms
- name: Schedule 30m host downtime in nagios
nagios: action=downtime minutes=60 service=host host={{ inventory_hostname_short }}{{ env_suffix }}
delegate_to: noc01.rdu3.fedoraproject.org
ignore_errors: true
- name: Pause for 30s before doing it
pause: seconds=30 prompt="Destroying (and lvremove for) vm now {{ target }}, abort if this is wrong"
- name: Destroy the vm
virt: name={{ inventory_hostname }} command=destroy
delegate_to: "{{ vmhost }}"
- name: Undefine the vm
virt: name={{ inventory_hostname }} command=undefine
delegate_to: "{{ vmhost }}"
- name: Destroy the lv
ansible.builtin.command: /sbin/lvremove -f {{volgroup}}/{{inventory_hostname}}
delegate_to: "{{ vmhost }}"