-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeployTemplateOpenShiftMultiVMs.yml
121 lines (118 loc) · 4.75 KB
/
DeployTemplateOpenShiftMultiVMs.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
118
119
120
121
---
# Deploy a VM from Template
- hosts: all
#Variables for vCenter and VMs
vars:
vcenter_ip: ""
vcenter_username: ""
vcenter_password: ""
#vm_name: ""
dc: ""
folder: ""
template: ""
datastore: ""
worker_vm_ram: ""
master_vm_ram: ""
bootstrap_vm_ram: ""
worker_vm_cpus: ""
master_vm_cpus: ""
bootstrap_vm_cpus: ""
#vm_cpu_cores_per_socket: ""
vm_disk_gb: ""
#vm_hostname: ""
worker1_vm_mac: ""
worker2_vm_mac: ""
master1_vm_mac: ""
master2_vm_mac: ""
master3_vm_mac: ""
bootstrap_vm_mac: ""
worker_ignition_file: ""
master_ignition_file: ""
bootstrap_ignition_file: ""
table_item_worker1: { vm_name: "testworker1", vm_ram: "{{ worker_vm_ram }}", vm_cpus: "{{ worker_vm_cpus }}", ignition_file: "{{ worker_ignition_file }}", vm_mac: "{{ worker1_vm_mac }}" }
table_item_worker2: { vm_name: "testworker2", vm_ram: "{{ worker_vm_ram }}", vm_cpus: "{{ worker_vm_cpus }}", ignition_file: "{{ worker_ignition_file }}", vm_mac: "{{ worker2_vm_mac }}" }
table_item_master1: { vm_name: "testmaster1", vm_ram: "{{ master_vm_ram }}", vm_cpus: "{{ master_vm_cpus }}", ignition_file: "{{ master_ignition_file }}", vm_mac: "{{ master1_vm_mac }}" }
table_item_master2: { vm_name: "testmaster2", vm_ram: "{{ master_vm_ram }}", vm_cpus: "{{ master_vm_cpus }}", ignition_file: "{{ master_ignition_file }}", vm_mac: "{{ master2_vm_mac }}" }
table_item_master3: { vm_name: "testmaster3", vm_ram: "{{ master_vm_ram }}", vm_cpus: "{{ master_vm_cpus }}", ignition_file: "{{ master_ignition_file }}", vm_mac: "{{ master3_vm_mac }}" }
table_item_bootstrap: { vm_name: "testbootstrap", vm_ram: "{{ bootstrap_vm_ram }}", vm_cpus: "{{ bootstrap_vm_cpus }}", ignition_file: "{{ bootstrap_ignition_file }}", vm_mac: "{{ bootstrap_vm_mac }}" }
tasks:
- name: Create a virtual machine from a template
vmware_guest:
hostname: "{{ vcenter_ip }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ dc }}"
folder: "{{ folder }}"
name: "{{ item.vm_name }}"
state: present
template: "{{ template }}"
disk:
- size_gb: "{{ vm_disk_gb }}"
type: thin
datastore: "{{ datastore }}"
hardware:
memory_mb: "{{ item.vm_ram }}"
mem_reservation: "{{ item.vm_ram }}"
num_cpus: "{{ item.vm_cpus }}" #For example to create a VM with 2 sockets of 4 cores, specify num_cpus: 8 and num_cpu_cores_per_socket: 4
#num_cpu_cores_per_socket: "{{ vm_cpu_cores_per_socket }}"
scsi: paravirtual
boot_firmware: "efi"
networks:
- name: "VM Network"
type: dhcp
with_items:
- "{{ table_item_worker1 }}"
- "{{ table_item_worker2 }}"
- "{{ table_item_master1 }}"
- "{{ table_item_master2 }}"
- "{{ table_item_master3 }}"
- "{{ table_item_bootstrap }}"
delegate_to: localhost
- name: change configuration parameter
vmware_guest_custom_attributes:
hostname: "{{ vcenter_ip }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ dc }}"
folder: "{{ folder }}"
name: "{{ item.vm_name }}"
state: present
attributes:
- name: guestinfo.ignition.config.data.encoding
value: "base64"
- name: disk.EnableUUID
value: "TRUE"
- name: guestinfo.ignition.config.data
value: "{{ item.ignition_file }}"
with_items:
- "{{ table_item_worker1 }}"
- "{{ table_item_worker2 }}"
- "{{ table_item_master1 }}"
- "{{ table_item_master2 }}"
- "{{ table_item_master3 }}"
- "{{ table_item_bootstrap }}"
delegate_to: localhost
- name: change mac address
vmware_guest_network:
hostname: "{{ vcenter_ip }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ dc }}"
folder: "{{ folder }}"
name: "{{ item.vm_name }}"
gather_network_info: false
networks:
- label: "Network adapter 1"
state: present
manual_mac: "{{ item.vm_mac }}"
with_items:
- "{{ table_item_worker1 }}"
- "{{ table_item_worker2 }}"
- "{{ table_item_master1 }}"
- "{{ table_item_master2 }}"
- "{{ table_item_master3 }}"
- "{{ table_item_bootstrap }}"
delegate_to: localhost