-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path05_delete-vm.yaml
More file actions
38 lines (33 loc) · 995 Bytes
/
05_delete-vm.yaml
File metadata and controls
38 lines (33 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
- name: Delete a VM on OpenShift Virtualization
hosts: localhost
connection: local
gather_facts: false
vars:
kubeconfig_path: "/root/ocp4/auth/kubeconfig"
namespace: "rhce-consulting-vms"
vm_name: "rhel9-vm"
tasks:
- name: Delete VirtualMachine
k8s:
kubeconfig: "{{ kubeconfig_path }}"
api_version: kubevirt.io/v1
kind: VirtualMachine
namespace: "{{ namespace }}"
name: "{{ vm_name }}"
state: absent
- name: Confirm VM deletion
k8s_info:
kubeconfig: "{{ kubeconfig_path }}"
api_version: kubevirt.io/v1
kind: VirtualMachine
namespace: "{{ namespace }}"
name: "{{ vm_name }}"
register: vm_info
failed_when: vm_info.resources | length > 0
retries: 5
delay: 4
until: vm_info.resources | length == 0
- name: Show deletion success message
debug:
msg: "Virtual Machine {{ vm_name }} has been successfully deleted."