-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.yml
294 lines (255 loc) · 11.5 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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
---
# create-inventory tasks
#
# For Multi Node OpenShift clusters:
# * First machine is bastion
# * Following 3 machines are controlplane nodes (master)
# * Remaining are worker nodes (depending upon worker_node_count)
#
# For Single Node OpenShift clusters:
# * First machine is bastion
# * Second machine is SNO cluster
#
- name: Set ocp inventory download url from lab wiki - scalelab
set_fact:
ocp_inventory_url: "https://{{ labs[lab]['quads'] }}/instack/{{ lab_cloud }}_ocpinventory.json"
when: ocp_inventory_override | string | length < 1 and lab == 'scalelab'
- name: Set ocp inventory download url from lab wiki - performancelab
set_fact:
ocp_inventory_url: "http://{{ labs[lab]['quads'] }}/cloud/{{ lab_cloud }}_ocpinventory.json"
when: ocp_inventory_override | string | length < 1 and lab == 'performancelab'
- name: Set ocp inventory download url to override
set_fact:
ocp_inventory_url: "{{ ocp_inventory_override }}"
when: ocp_inventory_override | string | length > 1
- name: Download ocpinventory.json
uri:
url: "{{ ocp_inventory_url }}"
return_content: true
register: ocpinventory
- name: Set inventory variables
set_fact:
bastion_machine: "{{ ocpinventory.json.nodes[0].pm_addr | replace('mgmt-','') }}"
bmc_user: "{{ ocpinventory.json.nodes[0].pm_user }}"
bmc_password: "{{ ocpinventory.json.nodes[0].pm_password }}"
ocpinventory_worker_nodes: []
ocpinventory_sno_nodes: []
ocpinventory_hv_nodes: []
- name: Public VLAN in BM cluster
when: public_vlan and cluster_type == "mno"
block:
- name: Public VLAN - Configuring controlplane_network_interface_idx to the last interface
set_fact:
controlplane_network_interface_idx: "{{ ocpinventory.json.nodes[0].mac | length - 1 }}"
- name: Get assignment from scalelab quads
uri:
url: "https://{{ labs[lab]['quads'] }}/api/v3/assignments/active/{{ lab_cloud }}"
force_basic_auth: yes
user: "{{ lab_cloud }}"
password: "{{ ocpinventory.json.nodes[0].pm_password }}"
validate_certs: false
register: quads_assignment
when: lab == "scalelab"
- name: Public scalelab VLAN - Set addressing information
set_fact:
controlplane_network: "{{ quads_assignment.json.vlan.ip_range }}"
controlplane_network_prefix: "{{ quads_assignment.json.vlan.ip_range | ipaddr('prefix') }}"
controlplane_network_gateway: "{{ quads_assignment.json.vlan.gateway }}"
cluster_name: "vlan{{ quads_assignment.json.vlan.vlan_id }}"
when: lab == "scalelab"
- name: Get VLAN info from performancelab quads
shell: |
set -o pipefail
curl -sk https://wiki.rdu3.labs.perfscale.redhat.com/vlans/ | grep -B7 {{ lab_cloud }} | sed -E 's#</?td>##g'| tr '\n' ' ' | column -J --table-columns vlan_id,cidr,netmask,gateway,ipfree,owner,ticket,cloud
register: vlan_info
when: lab == "performancelab"
- name: Public performancelab VLAN - Set addressing information
set_fact:
controlplane_network: "{{ (vlan_info.stdout | from_json).table[0].cidr }}"
controlplane_network_prefix: "{{ (vlan_info.stdout | from_json).table[0].cidr | ipaddr('prefix') }}"
controlplane_network_gateway: "{{ (vlan_info.stdout | from_json).table[0].gateway }}"
cluster_name: "vlan{{ (vlan_info.stdout | from_json).table[0].vlan_id }}"
when: lab == "performancelab"
- name: Multi node cluster type tasks
when: cluster_type == "mno"
block:
- name: MNO - Set inventory variables
set_fact:
controlplane0: "{{ ocpinventory.json.nodes[1].pm_addr }}"
controlplane1: "{{ ocpinventory.json.nodes[2].pm_addr }}"
controlplane2: "{{ ocpinventory.json.nodes[3].pm_addr }}"
controlplane0_mac_address: "{{ ocpinventory.json.nodes[1].mac[controlplane_network_interface_idx | int] }}"
controlplane1_mac_address: "{{ ocpinventory.json.nodes[2].mac[controlplane_network_interface_idx | int] }}"
controlplane2_mac_address: "{{ ocpinventory.json.nodes[3].mac[controlplane_network_interface_idx | int] }}"
controlplane0_vendor: "{{ hw_vendor[(ocpinventory.json.nodes[1].pm_addr.split('.')[0]).split('-')[-1]] }}"
controlplane1_vendor: "{{ hw_vendor[(ocpinventory.json.nodes[2].pm_addr.split('.')[0]).split('-')[-1]] }}"
controlplane2_vendor: "{{ hw_vendor[(ocpinventory.json.nodes[3].pm_addr.split('.')[0]).split('-')[-1]] }}"
- name: MNO - Get controlplane0 lab mac address
uri:
url: "https://{{ labs[lab]['foreman'] }}/api/hosts/{{ controlplane0 | replace('mgmt-','') }}"
force_basic_auth: yes
user: "{{ lab_cloud }}"
password: "{{ bmc_password }}"
validate_certs: false
register: controlplane0_foreman_data
- name: MNO - Set controlplane0 lab mac addresses
set_fact:
controlplane0_lab_mac: "{{ item.mac }}"
with_items: "{{ controlplane0_foreman_data.json.interfaces }}"
when: item.primary|bool
- name: MNO - Get controlplane1 lab mac address
uri:
url: "https://{{ labs[lab]['foreman'] }}/api/hosts/{{ controlplane1 | replace('mgmt-','') }}"
force_basic_auth: yes
user: "{{ lab_cloud }}"
password: "{{ bmc_password }}"
validate_certs: false
register: controlplane1_foreman_data
- name: MNO - Set controlplane1 lab mac addresses
set_fact:
controlplane1_lab_mac: "{{ item.mac }}"
with_items: "{{ controlplane1_foreman_data.json.interfaces }}"
when: item.primary|bool
- name: MNO - Get controlplane2 lab mac address
uri:
url: "https://{{ labs[lab]['foreman'] }}/api/hosts/{{ controlplane2 | replace('mgmt-','') }}"
force_basic_auth: yes
user: "{{ lab_cloud }}"
password: "{{ bmc_password }}"
validate_certs: false
register: controlplane2_foreman_data
- name: MNO - Set controlplane2 lab mac addresses
set_fact:
controlplane2_lab_mac: "{{ item.mac }}"
with_items: "{{ controlplane2_foreman_data.json.interfaces }}"
when: item.primary|bool
- name: MNO - Set max number of nodes
set_fact:
max_nodes: "{{ ocpinventory.json.nodes|length }}"
when: worker_node_count == None
- name: MNO - Set max number of nodes (worker_node_count set)
set_fact:
max_nodes: "{{ worker_node_count|int + 4 }}"
when: worker_node_count != None
- name: MNO - Set ocpinventory mno nodes
set_fact:
ocpinventory_worker_nodes: "{{ ocpinventory.json.nodes[4:max_nodes|int] }}"
- name: MNO - Set ocpinventory hv nodes
set_fact:
ocpinventory_hv_nodes: "{{ ocpinventory.json.nodes[max_nodes|int:] }}"
- name: MNO - Get lab mac address
uri:
url: "https://{{ labs[lab]['foreman'] }}/api/hosts/{{ item.pm_addr | replace('mgmt-','') }}"
force_basic_auth: yes
user: "{{ lab_cloud }}"
password: "{{ bmc_password }}"
validate_certs: false
with_items:
- "{{ ocpinventory_worker_nodes }}"
when: cluster_type == "mno"
register: mno_foreman_data
- name: Single Node OpenShift cluster type tasks
when: cluster_type == "sno"
block:
- name: SNO - Set max number of nodes
set_fact:
max_nodes: "1"
- name: SNO - Set ocpinventory sno nodes
set_fact:
ocpinventory_sno_nodes: "{{ ocpinventory.json.nodes[1:] }}"
- name: SNO - Get lab data for each sno
uri:
url: "https://{{ labs[lab]['foreman'] }}/api/hosts/{{ item.pm_addr | replace('mgmt-','') }}"
force_basic_auth: yes
user: "{{ lab_cloud }}"
password: "{{ bmc_password }}"
validate_certs: false
register: sno_foreman_data
loop: "{{ ocpinventory_sno_nodes }}"
- name: set json query fact
set_fact:
mac_query: "json.interfaces[?type=='interface'].mac"
- name: Loop over all OCP nodes to find Supermicro hardware
include_tasks: find_supermicro.yml
loop: "{{ ocpinventory.json.nodes }}"
- name: If no Supermicros found set fact
set_fact:
has_supermicro: false
when: has_supermicro is not defined
- name: Hypervisor tasks to determine if there is a 2nd disk available
when: hv_inventory
block:
- name: Disable disk2 for all hypervisor machines
set_fact:
ocpinventory_hv_nodes: "{{ ocpinventory_hv_nodes[:idx] + [ocpinventory_hv_nodes[idx] | combine({'disk2_enable': false, 'disk2_device': ''})] + ocpinventory_hv_nodes[idx + 1:] }}"
loop: "{{ ocpinventory_hv_nodes }}"
loop_control:
index_var: idx
- name: Enable disk2_enable for r630 with sdb
set_fact:
ocpinventory_hv_nodes: "{{ ocpinventory_hv_nodes[:idx] + [ocpinventory_hv_nodes[idx] | combine({'disk2_enable': true, 'disk2_device': 'sdb'})] + ocpinventory_hv_nodes[idx + 1:] }}"
when:
- (item.pm_addr.split('.')[0]).split('-')[-1] in ['r630']
loop: "{{ ocpinventory_hv_nodes }}"
loop_control:
index_var: idx
- name: Check for disk2 on r640
shell: |
lsblk -l -o NAME | egrep "nvme0n1$|sdb$" | sort | head -n 1
delegate_to: "{{ item.pm_addr | replace('mgmt-','') }}"
vars:
ansible_user: root
ansible_ssh_pass: "{{ hv_ssh_pass }}"
register: r640_disks
when:
- (item.pm_addr.split('.')[0]).split('-')[-1] in ['r640']
loop: "{{ ocpinventory_hv_nodes }}"
loop_control:
index_var: idx
- name: Enable disk2_enable for r640 with the captured extra disk
set_fact:
ocpinventory_hv_nodes: "{{ ocpinventory_hv_nodes[:idx] + [ocpinventory_hv_nodes[idx] | combine({'disk2_enable': true if (r640_disks.results)[idx].stdout else false, 'disk2_device': (r640_disks.results)[idx].stdout })] + ocpinventory_hv_nodes[idx + 1:] }}"
when:
- (item.pm_addr.split('.')[0]).split('-')[-1] in ['r640']
loop: "{{ ocpinventory_hv_nodes }}"
loop_control:
index_var: idx
- name: Enable disk2_enable for r660, r650, r750, r730xd, and r930 with nvme0n1
set_fact:
ocpinventory_hv_nodes: "{{ ocpinventory_hv_nodes[:idx] + [ocpinventory_hv_nodes[idx] | combine({'disk2_enable': true, 'disk2_device': 'nvme0n1'})] + ocpinventory_hv_nodes[idx + 1:] }}"
when:
- (item.pm_addr.split('.')[0]).split('-')[-1] in ['r650', 'r660', 'r750', 'r730xd', 'r930']
loop: "{{ ocpinventory_hv_nodes }}"
loop_control:
index_var: idx
# Skip fc640 type since it has no extra disk
# Skip 6018r type since it has only 2 80G disks
- name: Append disk2_enable for 6048r, 1029u and 1029p with nvme0n1
set_fact:
ocpinventory_hv_nodes: "{{ ocpinventory_hv_nodes[:idx] + [ocpinventory_hv_nodes[idx] | combine({'disk2_enable': true, 'disk2_device': 'nvme0n1'})] + ocpinventory_hv_nodes[idx + 1:] }}"
when:
- (item.pm_addr.split('.')[0]).split('-')[-1] in ['6048r', '1029u', '1029p']
loop: "{{ ocpinventory_hv_nodes }}"
loop_control:
index_var: idx
- name: Append disk2_enable for 5039ms and dl360 with sdb
set_fact:
ocpinventory_hv_nodes: "{{ ocpinventory_hv_nodes[:idx] + [ocpinventory_hv_nodes[idx] | combine({'disk2_enable': true, 'disk2_device': 'sdb'})] + ocpinventory_hv_nodes[idx + 1:] }}"
when:
- (item.pm_addr.split('.')[0]).split('-')[-1] in ['5039ms', 'dl360']
loop: "{{ ocpinventory_hv_nodes }}"
loop_control:
index_var: idx
- name: Append disk2_enable for 6049p with nvme0n1
set_fact:
ocpinventory_hv_nodes: "{{ ocpinventory_hv_nodes[:idx] + [ocpinventory_hv_nodes[idx] | combine({'disk2_enable': true, 'disk2_device': 'nvme0n1'})] + ocpinventory_hv_nodes[idx + 1:] }}"
when:
- (item.pm_addr.split('.')[0]).split('-')[-1] in ['6049p']
loop: "{{ ocpinventory_hv_nodes }}"
loop_control:
index_var: idx
- name: Place inventory file named {{ lab_cloud }}.local into inventory directory
template:
src: "inventory-{{ cluster_type }}.j2"
dest: "{{ playbook_dir }}/inventory/{{ lab_cloud }}.local"
backup: true