-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo_3.yml
101 lines (91 loc) · 2.93 KB
/
demo_3.yml
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
- name: VMWare Object Deletion
gather_facts: False
vars_files:
- vcenter_vars.yml
hosts: localhost
tasks:
- name: Poweroff virtual machine name {{ vm_name }}
vmware_guest_powerstate:
name: "{{ vm_name }}"
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
validate_certs: False
folder: "{{ folder }}"
state: powered-off
- name: Delete a virtual machine name {{ vm_name }}
vmware_guest:
name: "{{ vm_name }}"
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
validate_certs: False
folder: "{{ folder }}"
datacenter: "{{ datacenter }}"
state: absent
register: vm_result
- name: Assert that VM {{ vm_name }} is deleted
assert:
that:
- "vm_result.changed"
- name: Add ESXi {{ esxi_hostname }} to maintenance mode
vmware_maintenancemode:
validate_certs: False
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
esxi_hostname: "{{ esxi_hostname }}"
state: present
register: host_result
- name: Assert that host {{ esxi_hostname }} is in maintenance mode
assert:
that:
- "host_result.changed"
- name: Delete an existing ESXi {{ esxi_hostname }}
vmware_host:
validate_certs: False
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
datacenter_name: "{{ datacenter }}"
cluster_name: "{{ cluster }}"
esxi_hostname: "{{ esxi_hostname }}"
esxi_username: "{{ esxi_username }}"
esxi_password: "{{ esxi_password }}"
state: absent
register: host_result
- name: Assert that host is added
assert:
that:
- "host_result.changed"
- name: Delete a cluster {{ cluster }}
vmware_cluster:
validate_certs: False
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
datacenter_name: "{{ datacenter }}"
cluster_name: "{{ cluster }}"
state: absent
enable_ha: no
enable_drs: yes
enable_vsan: no
register: cluster_result
- name: Assert that cluster {{ cluster }} is deleted
assert:
that:
- "cluster_result.changed"
- name: Delete a datacenter {{ datacenter }}
vmware_datacenter:
validate_certs: False
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
datacenter_name: "{{ datacenter }}"
state: absent
register: datacenter_result
- name: Assert that datacenter {{ datacenter }} is deleted
assert:
that:
- "datacenter_result.changed"