/
main.yml
345 lines (307 loc) · 10.9 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
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
---
- name: set instance data
set_fact:
instance_data: "{{ instances[hostvars[inventory_hostname].instance_name] }}"
tags:
- always
- name: set instance name
set_fact:
instance_name: "{{ hostvars[inventory_hostname].instance_name }}"
tags:
- always
- name: set contrail configuration param
set_fact:
contrail_configuration: {}
when: contrail_configuration is undefined
tags:
- always
- name: set orchestrator param
set_fact:
contrail_configuration: "{{ contrail_configuration | combine({'CLOUD_ORCHESTRATOR': orchestrator | default('none')}) }}"
when:
- contrail_configuration.CLOUD_ORCHESTRATOR is not defined
tags:
- always
- name: set empty kolla_config sections in case of OpenStack
set_fact:
kolla_config: {}
when:
- contrail_configuration.CLOUD_ORCHESTRATOR == 'openstack'
- kolla_config is not defined
tags:
- always
- name: set empty kolla_global sections in case of OpenStack
set_fact:
kolla_config: "{{ kolla_config | combine({ 'kolla_globals': {} }) }}"
when:
- contrail_configuration.CLOUD_ORCHESTRATOR == 'openstack'
- kolla_config.kolla_globals is not defined
tags:
- always
- name: set empty kolla_passwords sections in case of OpenStack
set_fact:
kolla_config: "{{ kolla_config | combine({ 'kolla_passwords': {} }) }}"
when:
- contrail_configuration.CLOUD_ORCHESTRATOR == 'openstack'
- kolla_config.kolla_passwords is not defined
tags:
- always
- name: set container tag contrail version if defined
set_fact:
contrail_version_tag: "{{ contrail_configuration.CONTRAIL_VERSION | default('latest') }}"
tags:
- always
- name: add openstack version tag if defined
set_fact:
contrail_version_tag: "{{ contrail_configuration.OPENSTACK_VERSION }}-{{ contrail_version_tag }}"
when:
- contrail_configuration.CONTRAIL_VERSION is defined
- contrail_configuration.OPENSTACK_VERSION is defined
tags:
- always
- name: add linux distr tag if defined
set_fact:
contrail_version_tag: "{{ contrail_configuration.LINUX_DISTR }}-{{ contrail_version_tag }}"
when:
- contrail_configuration.CONTRAIL_VERSION is defined
- contrail_configuration.LINUX_DISTR is defined
tags:
- always
- name: set registry to opencontrailnightly if undefined
set_fact:
container_registry: opencontrailnightly
when: global_configuration is not defined or (global_configuration is defined and global_configuration.CONTAINER_REGISTRY is undefined)
tags:
- always
- name: set registry if defined
set_fact:
container_registry: "{{ global_configuration.CONTAINER_REGISTRY }}"
when:
- global_configuration is defined
- global_configuration.CONTAINER_REGISTRY is defined
tags:
- always
- name: activate docker login
shell: "docker login --username {{ global_configuration.CONTAINER_REGISTRY_USERNAME }} --password {{ global_configuration.CONTAINER_REGISTRY_PASSWORD }} {{ container_registry }}"
when:
- global_configuration is defined
- global_configuration.CONTAINER_REGISTRY_USERNAME is defined
- global_configuration.CONTAINER_REGISTRY_PASSWORD is defined
tags:
- always
- name: set stdin_open to true if it's not defined
set_fact:
stdin_open: "{{ contrail_configuration.STDIN_OPEN | default(true) }}"
tags:
- always
- name: set tty to true if it's not defined
set_fact:
tty: "{{ contrail_configuration.TTY | default(true) }}"
tags:
- always
- name: Evaluate roles
include: eval_node_roles.yml
tags:
- always
- name: add nodes to contrail_configuration
set_fact:
contrail_configuration: "{{ contrail_configuration | combine({item.name: item.nodes|join(',')}) }}"
when: contrail_configuration.get(item.name, 0) == 0 and item.nodes | length > 0
with_items:
- {'name': 'CONFIG_NODES', 'nodes': "{{config_nodes_list}}"}
- {'name': 'CONTROL_NODES', 'nodes': "{{control_nodes_list}}"}
- {'name': 'CONTROLLER_NODES', 'nodes': "{{control_nodes_list}}"}
- {'name': 'CONFIGDB_NODES', 'nodes': "{{configdb_nodes_list}}"}
- {'name': 'ANALYTICS_NODES', 'nodes': "{{analytics_nodes_list}}"}
- {'name': 'ANALYTICSDB_NODES', 'nodes': "{{analyticsdb_nodes_list}}"}
- {'name': 'WEBUI_NODES', 'nodes': "{{webui_nodes_list}}"}
- {'name': 'TSN_NODES', 'nodes': "{{tsn_nodes_list}}"}
- name: explicitly set OpenStack secrets for Contrail
set_fact:
contrail_configuration: "{{ contrail_configuration | combine({item.name: kolla_config.kolla_passwords.get(item.os_key) }) }}"
when:
- contrail_configuration.CLOUD_ORCHESTRATOR == 'openstack'
- item.is_defined | bool
tags:
- always
with_items:
- { name: 'KEYSTONE_AUTH_ADMIN_PASSWORD', os_key: 'keystone_admin_password', is_defined: "{{ kolla_config.kolla_passwords.keystone_admin_password is defined }}" }
- { name: 'METADATA_PROXY_SECRET', os_key: 'metadata_secret', is_defined: "{{ kolla_config.kolla_passwords.metadata_secret is defined }}" }
- name: get the internal VIP from openstack node if haproxy is disabled
set_fact:
openstack_internal_vip: "{{ openstack_nodes_list | first }}"
when:
- contrail_configuration.CLOUD_ORCHESTRATOR == 'openstack'
- kolla_config.kolla_globals.enable_haproxy is defined
- not (kolla_config.kolla_globals.enable_haproxy | bool)
tags:
- always
- name: get the internal VIP from internal_vip if haproxy is enabled
set_fact:
openstack_internal_vip: "{{ kolla_config.kolla_globals.kolla_internal_vip_address }}"
when:
- contrail_configuration.CLOUD_ORCHESTRATOR == 'openstack'
- kolla_config.kolla_globals.enable_haproxy is not defined or (kolla_config.kolla_globals.enable_haproxy | bool)
tags:
- always
- name: set OpenStack endpoints from kolla_config.kolla_globals
set_fact:
contrail_configuration: "{{ contrail_configuration | combine({item.name: openstack_internal_vip }) }}"
when:
- item.is_not_defined | bool
- contrail_configuration.CLOUD_ORCHESTRATOR == 'openstack'
tags:
- always
with_items:
- { name: 'KEYSTONE_AUTH_HOST', is_not_defined: "{{ contrail_configuration.KEYSTONE_AUTH_HOST is not defined }}" }
- { name: 'IPFABRIC_SERVICE_HOST', is_not_defined: "{{ contrail_configuration.IPFABRIC_SERVICE_HOST is not defined }}" }
- { name: 'computeManager_ip', is_not_defined: "{{ contrail_configuration.computeManager_ip is not defined }}" }
- { name: 'imageManager_ip', is_not_defined: "{{ contrail_configuration.imageManager_ip is not defined }}" }
- { name: 'networkManager_ip', is_not_defined: "{{ contrail_configuration.networkManager_ip is not defined }}" }
- name: Evaluate k8s master ip/name
include: set_master.yml
when:
- roles[instance_name].k8s_master is defined or roles[instance_name].k8s_node is defined or roles[instance_name].kubemanager is defined
tags:
- k8s
- name: create /var/log/contrail
file:
path: /var/log/contrail
state: directory
recurse: yes
tags:
- always
- name: create /etc/contrail/compose
file:
path: /etc/contrail/compose
state: directory
recurse: yes
tags:
- always
- name: get /etc/contrail/common.env stat
stat:
path: /etc/contrail/common.env
register: st
tags:
- always
- name: delete /etc/contrail/common.env if exists
file:
path: /etc/contrail/common.env
state: absent
when: st.stat.exists is defined and st.stat.exists
tags:
- always
- name: create /etc/contrail/common.env
file:
path: /etc/contrail/common.env
state: touch
tags:
- always
- name: populate common.env
lineinfile: dest=/etc/contrail/common.env regexp='.*{{ item.key }}$' line="{{ item.key }}={{ item.value }}" state=present
no_log: True
with_dict: "{{ contrail_configuration }}"
tags:
- always
no_log: True
- name: create redis
include: create_redis.yml
when: roles[instance_name].webui is defined or roles[instance_name].analytics is defined
tags:
- webui
- analytics
- name: create contrail config datqbase
include: create_config_database.yml
when: roles[instance_name].config_database is defined
tags:
- config_database
- name: create contrail config
include: create_config.yml
when: roles[instance_name].config is defined
tags:
- config
- name: create contrail webui
include: create_webui.yml
when: roles[instance_name].webui is defined
tags:
- webui
- name: create contrail control
include: create_control.yml
when: roles[instance_name].control is defined
tags:
- control
- name: create contrail control_only
include: create_control_only.yml
when: roles[instance_name].control_only is defined
tags:
- control_only
- name: create contrail analytics database
include: create_analytics_database.yml
when: roles[instance_name].analytics_database is defined
tags:
- analytics_database
- name: create contrail analytics
include: create_analytics.yml
when: roles[instance_name].analytics is defined
tags:
- analytics
- name: create cni
include: create_k8s_cni.yml
when: roles[instance_name].k8s_node is defined
tags:
- k8s
- name: configure k8s master
include: configure_k8s_master_node.yml
when: roles[instance_name].k8s_master is defined and k8s_master_name is defined and inventory_hostname == k8s_master_name
tags:
- k8s
- name: create contrail vrouter
include: create_vrouter.yml
when: roles[instance_name].vrouter is defined
tags:
- vrouter
- name: Pluginize legacy compute
include: compute_legacy.yml
when: roles[instance_name].openstack_compute_legacy is defined
- name: join k8s master
include: configure_k8s_join_node.yml
when: roles[instance_name].k8s_node is defined and k8s_master_name is defined and inventory_hostname != k8s_master_name
tags:
- k8s
- name: create k8s dashboard
include: create_k8s_dashboard.yml
when: roles[instance_name].k8s_master is defined and k8s_master_name is defined and inventory_hostname == k8s_master_name
tags:
- k8s
- name: create contrail kube manager
include: create_kubemanager.yml
when: roles[instance_name].kubemanager is defined and k8s_master_ip is defined and k8s_master_name is defined
tags:
- k8s
- name: create contrail vcenter-plugin
include: create_vcenter_plugin.yml
when:
- contrail_configuration.CLOUD_ORCHESTRATOR == 'vcenter'
- roles[instance_name].vcenter_plugin is defined
tags:
- vcenter
- name: create contrail vcenter-manager
include: create_vcenter_manager.yml
when:
- contrail_configuration.CLOUD_ORCHESTRATOR == 'vcenter'
- roles[instance_name].vcenter_manager is defined
tags:
- vcenter
- name: untaint node
shell: "kubectl taint nodes {{ hostvars[instance.value.ip]['ansible_fqdn'] }} node-role.kubernetes.io/master-"
with_dict: "{{ hostvars['localhost']['instances'] }}"
loop_control:
loop_var: instance
when:
- roles[instance_name].k8s_master is defined
- k8s_master_name is defined
- inventory_hostname == k8s_master_name
- instance.value.roles is defined
- instance.value.roles.k8s_node is defined
- instance.value.roles.k8s_master is defined
ignore_errors: yes