-
Notifications
You must be signed in to change notification settings - Fork 16
/
composable_prepare_nic_configs.yml
346 lines (297 loc) · 14.1 KB
/
composable_prepare_nic_configs.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
---
- hosts: localhost
vars:
undercloud_host: "{{ groups.undercloud|first }}"
tasks:
- name: get subnet mask
shell: |
echo {{ cidr }} | cut -d '/' -f2
register: prefix
- name: set subnet mask
set_fact:
subnet_mask: "{{ prefix.stdout }}"
- name: set machine count
set_fact:
machine_count: {}
- name: get machine count
set_fact:
machine_count: "{{ machine_count | combine({item: (item in machine_count)|ternary(machine_count[item], 0)|int + 1 }, recursive=True) }}"
with_items: "{{ machine_types }}"
- block:
- name: set fact rhel8_interfaces
set_fact:
rhel8_interfaces: "{{ rhel8_interfaces|default([]) + [ (item.1 == 'r640' and item.0.stdout.split('-')[0] == 'f04') | ternary('rhel8_interfaces_f04', 'rhel8_interfaces') ] }}"
with_together:
- "{{ host_list.results }}"
- "{{ machine_types }}"
- name: set fact rhel7_interfaces
set_fact:
rhel7_interfaces: "{{ rhel7_interfaces|default([]) + [ (item.1 == 'r640' and item.0.stdout.split('-')[0] == 'f04') | ternary('rhel7_interfaces_f04', 'rhel7_interfaces') ] }}"
with_together:
- "{{ host_list.results }}"
- "{{ machine_types }}"
- name: set fact for iface_rhel_version
set_fact:
iface_rhel_version: "{{ iface_rhel_version|default([]) + [(osp_release|int > 14)| ternary( item.0, item.1)] }}"
with_together:
- "{{ rhel8_interfaces }}"
- "{{ rhel7_interfaces }}"
# dict key is the machine type and value is interfaces
- name: set machine_ifaces
set_fact:
machine_ifaces: "{{ machine_ifaces|default({}) | combine({ item[1]: lab_vars['machine_types'][item[0]][item[1]][item[2]] }) }}"
with_together:
- "{{ vendors }}"
- "{{ machine_types }}"
- "{{ iface_rhel_version }}"
vars:
lab_vars: "{{ (lab_name == 'scale') | ternary(scale, alias) }}"
when: lab_name in ['scale', 'alias'] and osp_release|int < 17
- block:
- name: set fact for rhel 9 interfaces
set_fact:
rhel9_interfaces: "{{ rhel9_interfaces|default([]) + [ (item.1 == 'r640' and item.0.stdout.split('-')[0] == 'f04') | ternary('rhel9_interfaces_f04', 'rhel9_interfaces') ] }}"
with_together:
- "{{ host_list.results }}"
- "{{ machine_types }}"
# dict key is the machine type and value is interfaces
- name: set machine_ifaces
set_fact:
machine_ifaces: "{{ machine_ifaces|default({}) | combine({ item[1]: lab_vars['machine_types'][item[0]][item[1]][item[2]] }) }}"
with_together:
- "{{ vendors }}"
- "{{ machine_types }}"
- "{{ rhel9_interfaces }}"
vars:
lab_vars: "{{ (lab_name == 'scale') | ternary(scale, alias) }}"
when: lab_name in ['scale', 'alias'] and osp_release|int >= 17
- name: set interfaces
set_fact:
ifaces: "{{ ifaces|default([]) + [ machine_ifaces[item]] }}"
with_items:
- "{{ machine_types|unique }}"
when: lab_name in ['scale', 'alias']
#todo for non scale/alias machines
- name: interfaces is empty
fail:
msg: other lab types should specify interfaces
when: (ifaces is defined) and (ifaces|length == 0)
# br-isolated will be always first interface, followed by br-ctlplane,
# br-tenant and br-external. br-external and br-ctlplane will be shared if
# no separate nic avaialble for external interface.
- name: set control interfaces for custom roles
set_fact:
ctlplane_interfaces: "{{ ctlplane_interfaces|default([]) +[(item|length > 1)| ternary(item[1], item[0])] }}"
with_items:
- "{{ ifaces }}"
- name: set external interface for custom roles
set_fact:
external_interfaces: "{{ external_interfaces|default([]) + [(item|length > 3) | ternary(item[3], item[1] )] }}"
when: item|length > 1
with_items:
- "{{ ifaces }}"
- name: set external interface for custom roles
set_fact:
external_interfaces: "{{ external_interfaces|default([]) + [(item|length > 3) | ternary(item[3], item[0] )] }}"
when: item|length == 1
with_items:
- "{{ ifaces }}"
- name: set tenant interface for custom roles
set_fact:
tenant_interfaces: "{{ tenant_interfaces|default([]) + [item[2]] }}"
when: item|length > 2
with_items:
- "{{ ifaces }}"
- name: set isolated interface for custom roles
set_fact:
isolated_interfaces: "{{ isolated_interfaces|default([])+ [item[0]] }}"
when: item|length > 1
with_items:
- "{{ ifaces }}"
- name: set storage interface for custom roles
set_fact:
storage_interfaces: "{{ isolated_interfaces }}"
when: ceph_enabled and isolated_interfaces is defined
- name: set dedicated vlan based provider network
set_fact:
openshift_vlan_interfaces: "{{ openshift_vlan_interfaces|default([]) + [item[2]] }}"
when: item|length > 2
with_items:
- "{{ ifaces }}"
- name: remove duplicates from machine types
set_fact:
machine_types: "{{ machine_types | unique }}"
- name: set nic configs
set_fact:
nic_configs: "{{ ansible_user_dir }}/virt"
- name: create nic-configs directory structure in infrared format
file:
path: "{{ ansible_user_dir }}/virt/network/vlans/legacy"
state: directory
# infrared uses nic configs under 'legacy' directory for osp release version 10
- name: set nic-config path
set_fact:
nic_config_path: "{{ ansible_user_dir }}/virt/network/vlans{{ ((osp_release|int > 10) | ternary('', '/legacy')) }}"
- name: prepare network-environment.yaml.j2
template:
src: "network-environment.yaml.j2"
dest: "{{ ansible_user_dir }}/virt/network/network-environment.yaml.j2"
force: yes
when: osp_release|int < 17
- name: set fact controller machine type
set_fact:
controller_machine_type: "{{ (machine_count[machine_types[0]]|int >= controller_count|int)| ternary(machine_types[0], false) }}"
when: controller_machine_type is not defined
- name: set fact controller machine type
set_fact:
controller_machine_type: "{{ (machine_count[controller_machine_type]|int >= controller_count|int) | ternary(controller_machine_type, false) }}"
when: controller_machine_type is defined
- name: fail when controller_machine_type is false
fail:
msg: Not enough nodes of same machine_type for controller
when: controller_machine_type == false
- name: identify the controller_ifaces
set_fact:
controller_ifaces: "{{ machine_ifaces[controller_machine_type] }}"
- name: Executed when user specifies controller_ifaces
block:
- name: set fact for controller ifaces ctlplane and external
set_fact:
controller_ctlplane_interface: "{{ (controller_ifaces|length > 1) | ternary(controller_ifaces[1], controller_ifaces[0]) }}"
controller_external_interface: "{{ (controller_ifaces|length > 3) | ternary(controller_ifaces[3], controller_ctlplane_interface) }}"
- name: set fact for controller tenant ifaces
set_fact:
controller_tenant_interface: "{{ controller_ifaces[2] }}"
when: controller_ifaces|length > 2
- name: set fact for controller isolated_interface
set_fact:
controller_isolated_interface: "{{ controller_ifaces[0] }}"
when: controller_ifaces|length > 1
when: controller_ifaces is defined
- name: prepare controller.yaml.j2
vars:
ctlplane_interface: "{{ controller_ctlplane_interface | default(ctlplane_interfaces[0]) }}"
external_interface: "{{ controller_external_interface | default(external_interfaces[0]) }}"
tenant_interface: "{{ controller_tenant_interface | default(tenant_interfaces[0]) }}"
isolated_interface: "{{ controller_isolated_interface | default(isolated_interfaces[0]) }}"
openshift_vlan_interface: "{{ controller_tenant_interface | default(openshift_vlan_interfaces[0]) }}"
template:
src: "{{ (osp_release|int > 10) | ternary('controller.yaml.j2', false) }}"
dest: "{{ nic_config_path }}/controller.yaml.j2"
force: yes
when: osp_release|int < 17
- name: prepare compute.yaml.j2
vars:
ctlplane_interface: "{{ item.1 }}"
external_interface: "{{ item.2 }}"
tenant_interface: "{{ item.3 }}"
isolated_interface: "{{ item.4 }}"
openshift_vlan_interface: "{{ item.5 }}"
template:
src: "{{ (osp_release|int > 10) | ternary('compute.yaml.j2', false) }}"
dest: "{{ nic_config_path }}/compute_{{ item.0 }}.yaml.j2"
force: yes
with_together:
- "{{ machine_types }}"
- "{{ ctlplane_interfaces }}"
- "{{ external_interfaces }}"
- "{{ tenant_interfaces }}"
- "{{ isolated_interfaces }}"
- "{{ openshift_vlan_interfaces }}"
when: osp_release|int < 17
- block:
- name: set fact ceph machine type
set_fact:
ceph_machine_type: "{{ (machine_count[ceph_machine_type]|int >= ceph_node_count|int) | ternary(ceph_machine_type, false) }}"
- name: fail when insufficient nodes for ceph
fail:
msg: Not enough nodes of same machine_type for ceph
when: ceph_machine_type == false
- name: identify the ceph_ifaces
set_fact:
ceph_ifaces: "{{ machine_ifaces[ceph_machine_type] }}"
- name: set fact for ceph ext iface
set_fact:
ceph_external_interface: "{{ (ceph_ifaces|length > 1) | ternary(ceph_ifaces[1], ceph_ifaces[0]) }}"
ceph_ctlplane_interface: "{{ (ceph_ifaces|length > 1) | ternary(ceph_ifaces[1], ceph_ifaces[0]) }}"
- name: set fact for ceph storage iface
set_fact:
ceph_storage_interface: "{{ ceph_ifaces[0] }}"
when: ceph_ifaces|length > 1
- name: prepare ceph-storage.yaml.j2
vars:
ctlplane_interface: "{{ ceph_ctlplane_interface }}"
external_interface: "{{ ceph_external_interface }}"
storage_interface: "{{ ceph_storage_interface }}"
template:
src: ceph-storage.yaml.j2
dest: "{{ nic_config_path }}/ceph-storage.yaml.j2"
force: yes
when: osp_release|int < 17
when: ceph_enabled
- name: subtract the pci nodes from the the machine count
set_fact:
machine_count: "{{ machine_count | combine({item.key: (item.value |int - ((item.key == pci_node_type)|ternary(pci_node_count, 0)))}) }}"
with_dict: "{{ machine_count }}"
when: passthrough_nvme is defined and pci_node_count is defined
- block:
- name: prepare network-environment_v2.yaml.j2
template:
src: network-environment_v2.yaml.j2
dest: "{{ ansible_user_dir }}/virt/network/network-environment_v2.yaml.j2"
- name: prepare network_data_v2.yaml.j2
template:
src: network_data_v2.yaml.j2
dest: "{{ ansible_user_dir }}/virt/network/network_data_v2.yaml.j2"
- name: prepare vip_data.yaml.j2
template:
src: vip_data.yaml.j2
dest: "{{ ansible_user_dir }}/virt/network/vip_data.yaml.j2"
- name: Create nic_config_path dir
file:
path: "~/virt/network/vlans/"
state: directory
delegate_to: undercloud
- name: prepare controller.j2.j2
vars:
ctlplane_interface: "{{ controller_ctlplane_interface | default(ctlplane_interfaces[0]) }}"
external_interface: "{{ controller_external_interface | default(external_interfaces[0]) }}"
tenant_interface: "{{ controller_tenant_interface | default(tenant_interfaces[0]) }}"
isolated_interface: "{{ controller_isolated_interface | default(isolated_interfaces[0]) }}"
openshift_vlan_interface: "{{ controller_tenant_interface | default(openshift_vlan_interfaces[0]) }}"
template:
src: controller.j2.j2
dest: "~/virt/network/vlans/controller.j2"
force: yes
delegate_to: undercloud
- name: prepare compute.j2.j2
vars:
ctlplane_interface: "{{ item.1 }}"
external_interface: "{{ item.2 }}"
tenant_interface: "{{ item.3 }}"
isolated_interface: "{{ item.4 }}"
openshift_vlan_interface: "{{ item.5 }}"
template:
src: compute.j2.j2
dest: "~/virt/network/vlans//compute_{{ item.0 }}.j2"
force: yes
delegate_to: undercloud
with_together:
- "{{ machine_types }}"
- "{{ ctlplane_interfaces }}"
- "{{ external_interfaces }}"
- "{{ tenant_interfaces }}"
- "{{ isolated_interfaces }}"
- "{{ openshift_vlan_interfaces }}"
- name: prepare ceph-storage.j2.j2
vars:
ctlplane_interface: "{{ ceph_ctlplane_interface }}"
external_interface: "{{ ceph_external_interface }}"
storage_interface: "{{ ceph_storage_interface }}"
template:
src: ceph-storage.j2.j2
dest: "~/virt/network/vlans/ceph-storage.j2"
force: yes
delegate_to: undercloud
when: ceph_enabled
when: osp_release|int >= 17