-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep_ocp_v4_ignition.yml
281 lines (256 loc) · 9.27 KB
/
prep_ocp_v4_ignition.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
---
- name: Prepare OpenShift 4 Ignition and Install Files
hosts: all
gather_facts: no
tasks:
- name: Include ignition cluster vars
include_vars:
file: "vars/cluster_ignition_{{ clustertype | default('bm') }}.yml"
- name: Render profile templates
template:
src: "ignition.profile.json.j2"
dest: "/var/lib/matchbox/profiles/{{ item }}.json"
loop:
- bootstrap
- worker
- master
- name: Render matchbox bootstrap group templates
template:
src: bootstrap.json.j2
dest: "/var/lib/matchbox/groups/{{ cluster_name }}.{{ base_domain }}.{{ pref_bootstrap }}-{{ item.index }}.json"
loop: "{{ hosts_bootstrap }}"
- name: Render matchbox master group templates
template:
src: master.json.j2
dest: "/var/lib/matchbox/groups/{{ cluster_name }}.{{ base_domain }}.{{ pref_control_plane }}-{{ item.index }}.json"
loop: "{{ hosts_control_plane }}"
- name: Render matchbox worker group templates
template:
src: compute.json.j2
dest: "/var/lib/matchbox/groups/{{ cluster_name }}.{{ base_domain }}.{{ pref_compute }}-{{ item.index }}.json"
loop: "{{ hosts_compute }}"
- name: Create backend and frontend definitions for HAproxy
blockinfile:
block: "{{ lookup('template', 'templates/haproxy.j2') }}"
dest: /etc/haproxy/haproxy.cfg
marker: "## {mark} OCP4 Cluster {{ cluster_name }} ##"
insertafter: EOF
state: "{{ lb_block_state | default('present') }}"
- name: Force removal of local OpenShift Installation directory to clear contents
file:
path: "/tmp/ocp4-install-{{ cluster_name }}"
state: absent
delegate_to: "{{ openshift_install_host }}"
- name: Create local OpenShift Installation directory
file:
path: "/tmp/ocp4-install-{{ cluster_name }}"
state: directory
delegate_to: "{{ openshift_install_host }}"
- name: Render install-config.yaml
template:
src: install-config-baremetal.yaml.j2
dest: "/tmp/ocp4-install-{{ cluster_name }}/install-config.yaml"
delegate_to: "{{ openshift_install_host }}"
- name: Generate Ignition Configs
shell: |
openshift-install --dir=/tmp/ocp4-install-{{ cluster_name }} create ignition-configs
delegate_to: "{{ openshift_install_host }}"
- name: Slurp Ignition Configs
slurp:
src: "/tmp/ocp4-install-{{ cluster_name }}/{{ item }}.ign"
loop:
- bootstrap
- master
- worker
register: ignconf
delegate_to: "{{ openshift_install_host }}"
- name: Slurp kubeconfig
slurp:
src: "/tmp/ocp4-install-{{ cluster_name }}/auth/kubeconfig"
register: kubeconf
delegate_to: "{{ openshift_install_host }}"
- name: Prepare kubeconfig on Openshift Install host
file:
path: "/root/.kube"
state: directory
delegate_to: "{{ openshift_install_host }}"
- name: Place kubeconfig on Openshift Install host
copy:
content: "{{ kubeconf['content'] | b64decode }}"
dest: "/root/.kube/config"
delegate_to: "{{ openshift_install_host }}"
- name: Create local OpenShift Installation directory
file:
path: "/var/lib/matchbox/{{ item }}"
state: directory
loop:
- ignition
- name: Place Ignition YAML Configs on Matchbox using APPEND
template:
src: "ignition-template.yaml.j2"
dest: "/var/lib/matchbox/ignition/{{ item.item }}.yaml"
loop: "{{ ignconf.results }}"
no_log: True
##########
- name: Prepare OpenShift 4 UPI Hosts
hosts: localhost
gather_facts: no
vars:
esxi_hostname: "{{ vc_hostname }}"
esxi_username: "{{ vc_username }}"
esxi_password: "{{ vc_password }}"
esxi_datacenter: "{{ vc_datacenter }}"
esxi_cluster: "{{ vc_cluster }}"
vmstate: present
tasks:
- name: Include ignition cluster vars
include_vars:
file: "vars/cluster_ignition_{{ clustertype | default('bm') }}.yml"
- name: Create vCenter folder for cluster
vmware_resource_pool:
validate_certs: no
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
datacenter: "{{ esxi_datacenter | default('ha-datacenter') }}"
cluster: "{{ esxi_cluster }}"
resource_pool: "{{ cluster_name }}"
state: present
when: vmstate is defined and vmstate != 'absent'
- name: BOOTSTRAP Provision VMware Instances
async: 7200
poll: 0
vmware_guest:
validate_certs: no
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
esxi_hostname: "{{ esxi_target_hostname | default(esxi_hostname) }}"
datacenter: "{{ esxi_datacenter | default('ha-datacenter') }}"
name: "{{ cluster_name }}-{{ pref_bootstrap }}-{{ item.index }}"
folder: "/{{ esxi_datacenter | default('ha-datacenter') }}/{{ esxi_folder | default('vm') }}"
resource_pool: "{{ cluster_name }}"
disk:
- size_gb: 60
type: thin
datastore: "{{ esxi_datastore }}"
networks:
- device_type: vmxnet3
name: "{{ esxi_net | default('VM Network') }}"
mac: "{{ item.mac }}"
ip: "{{ item. ip }}"
netmask: "{{ ign_net_mask }}"
gateway: "{{ ign_net_gw }}"
dns_servers:
- "{{ ign_net_dns }}"
guest_id: "{{ esxi_guestid | default('centos64Guest') }}"
hardware:
memory_mb: "{{ hostvars[item]['memory'] | default('8096') }}"
num_cpus: "{{ hostvars[item]['cpu'] | default('4') }}"
scsi: paravirtual
hotadd_memory: True
state: "{{ vmstate | default('poweredon') }}"
force: yes
register: vms
loop: "{{ hosts_bootstrap }}"
- name: BOOTSTRAP Wait for instance launch completion
async_status: jid="{{ item.ansible_job_id }}"
register: vms_jobs
until: vms_jobs.finished
retries: 300
loop: "{{ vms.results }}"
- name: MASTER Provision VMware Instances
async: 7200
poll: 0
vmware_guest:
validate_certs: no
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
esxi_hostname: "{{ esxi_target_hostname | default(esxi_hostname) }}"
datacenter: "{{ esxi_datacenter | default('ha-datacenter') }}"
name: "{{ cluster_name }}-{{ pref_control_plane }}-{{ item.index }}"
resource_pool: "{{ cluster_name }}"
folder: "/{{ esxi_datacenter | default('ha-datacenter') }}/{{ esxi_folder | default('vm') }}"
disk:
- size_gb: 60
type: thin
datastore: "{{ esxi_datastore }}"
networks:
- device_type: vmxnet3
name: "{{ esxi_net | default('VM Network') }}"
mac: "{{ item.mac }}"
ip: "{{ item. ip }}"
netmask: "{{ ign_net_mask }}"
gateway: "{{ ign_net_gw }}"
dns_servers:
- "{{ ign_net_dns }}"
guest_id: "{{ esxi_guestid | default('centos64Guest') }}"
hardware:
memory_mb: "{{ hostvars[item]['memory'] | default('8096') }}"
num_cpus: "{{ hostvars[item]['cpu'] | default('4') }}"
scsi: paravirtual
hotadd_memory: True
state: "{{ vmstate | default('poweredon') }}"
force: yes
register: vms
loop: "{{ hosts_control_plane }}"
- name: MASTER Wait for instance launch completion
async_status: jid="{{ item.ansible_job_id }}"
register: vms_jobs
until: vms_jobs.finished
retries: 300
loop: "{{ vms.results }}"
- name: WORKER Provision VMware Instances
async: 7200
poll: 0
vmware_guest:
validate_certs: no
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
esxi_hostname: "{{ esxi_target_hostname | default(esxi_hostname) }}"
datacenter: "{{ esxi_datacenter | default('ha-datacenter') }}"
name: "{{ cluster_name }}-{{ pref_compute }}-{{ item.index }}"
resource_pool: "{{ cluster_name }}"
folder: "/{{ esxi_datacenter | default('ha-datacenter') }}/{{ esxi_folder | default('vm') }}"
disk:
- size_gb: 60
type: thin
datastore: "{{ esxi_datastore }}"
networks:
- device_type: vmxnet3
name: "{{ esxi_net | default('VM Network') }}"
mac: "{{ item.mac }}"
ip: "{{ item. ip }}"
netmask: "{{ ign_net_mask }}"
gateway: "{{ ign_net_gw }}"
dns_servers:
- "{{ ign_net_dns }}"
guest_id: "{{ esxi_guestid | default('centos64Guest') }}"
hardware:
memory_mb: "{{ hostvars[item]['memory'] | default('8096') }}"
num_cpus: "{{ hostvars[item]['cpu'] | default('4') }}"
scsi: paravirtual
hotadd_memory: True
state: "{{ vmstate | default('poweredon') }}"
force: yes
register: vms_compute
loop: "{{ hosts_compute }}"
- name: WORKER Wait for instance launch completion
async_status: jid="{{ item.ansible_job_id }}"
register: vms_jobs
until: vms_jobs.finished
retries: 300
loop: "{{ vms_compute.results }}"
- name: Remove vCenter folder for cluster
vmware_resource_pool:
validate_certs: no
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
datacenter: "{{ esxi_datacenter | default('ha-datacenter') }}"
cluster: "{{ esxi_cluster }}"
resource_pool: "{{ cluster_name }}"
state: absent
when: vmstate is defined and vmstate == 'absent'