-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.yml
117 lines (107 loc) · 3.83 KB
/
main.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
- block:
- name: Import common vars
ansible.builtin.include_vars:
file: ../group_vars.yml
when: not run_on_simulator
- name: "Test setup: Create VM guest {{ vm }}"
community.vmware.vmware_guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster: "{{ vm_cluster }}"
datacenter: "{{ vm_datacenter }}"
folder: "{{ vm_folder }}"
state: present
name: "{{ vm }}"
disk: "{{ vm_disk }}"
guest_id: "{{ vm_guest_id }}"
hardware: "{{ vm_hardware }}"
when: not run_on_simulator
- name: "Test setup: Create content library {{ library }}"
community.vmware.vmware_content_library_manager:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datastore_name: "{{ datastore }}"
library_name: "{{ library }}"
state: present
library_type: local
when: not run_on_simulator
- name: Create template from vm in content library
vmware.vmware.content_template:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
port: "{{ vcenter_port }}"
template: "{{ template_name }}"
library: "{{ library }}"
vm_name: "{{ vm }}"
host: "{{ template_host }}"
register: __res
- name: Assert values
ansible.builtin.assert:
that:
- __res.changed == False
- __res.template_info.msg == "Template '" + template_name + "' already exists."
when: run_on_simulator
- name: Assert values
ansible.builtin.assert:
that:
- __res.changed == True
- __res.template_info.msg == "Template '" + template_name + "'."
when: not run_on_simulator
- name: Delete template from content library
vmware.vmware.content_template:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
port: "{{ vcenter_port }}"
template: "{{ template_name }}"
library: "{{ library }}"
vm_name: "{{ vm }}"
host: "{{ template_host }}"
state: absent
when: not run_on_simulator
- name: Check for deleted template
vmware.vmware.content_library_item_info:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
port: "{{ vcenter_port }}"
library_name: "{{ library }}"
library_item_name: "{{ template_name }}"
register: __res
when: not run_on_simulator
- name: Verify Template Was Deleted
ansible.builtin.assert:
that: (__res.library_item_info | length) == 0
when: not run_on_simulator
always:
- name: "Test teardown: Destroy VM guest {{ vm }}"
community.vmware.vmware_guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster: "{{ vm_cluster }}"
datacenter: "{{ vm_datacenter }}"
folder: "{{ vm_folder }}"
state: absent
force: true
name: "{{ vm }}"
when: not run_on_simulator
- name: "Test teardown: Remove content library {{ library }}"
community.vmware.vmware_content_library_manager:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
library_name: "{{ library }}"
state: absent
when: not run_on_simulator