Playbook #1

/root/kubeinit/ci/builds/bsU8uCNn/0/kubeinit/kubeinit/kubeinit-aux/kubeinit/playbook.yml

Report Status CLI Date Duration Controller User Versions Hosts Plays Tasks Results Files Records
05 May 2024 07:01:27 +0000 00:15:38.91 nyctea root Ansible 2.15.2 ara 1.6.1 (client), 1.6.1 (server) Python 3.11.4 9 7 1009 1076 51 1

File: /root/.ansible/collections/ansible_collections/kubeinit/kubeinit/roles/kubeinit_prepare/tasks/gather_kubeinit_facts.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
---
# Copyright kubeinit contributors
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

#
# Gather kubeinit facts
#

- name: Load kubeinit_defaults group
  ansible.builtin.add_host:
    name: 'kubeinit-defaults'
    groups: 'kubeinit_defaults'

- name: Gather kubeinit secrets
  ansible.builtin.include_role:
    name: kubeinit.kubeinit.kubeinit_prepare
    tasks_from: gather_kubeinit_secrets.yml
    public: true
  vars:
    _param_secret_names:
      - dockerhub-username
      - dockerhub-password
      - openshift-pullsecret

- name: Parse kubeinit_network_spec into a dictionary when defined
  ansible.builtin.set_fact:
    kubeinit_network_map: "{{ kubeinit_network_spec | from_yaml }}"
  when: kubeinit_network_spec is defined

- name: Define kubeinit_network_name
  ansible.builtin.set_fact:
    kubeinit_network_name: "{{ kubeinit_network_map['network_name'] | default(hostvars['kubeinit-defaults'].default_network_name) }}"

- name: Use kubeinit_network_name as host for kubeinit_network group and load default properties
  ansible.builtin.add_host:
    name: "{{ kubeinit_network_name }}"
    groups: 'kubeinit_network'

- name: Add kubeinit_network_map entries to kubeint_network group
  ansible.builtin.add_host:
    name: "{{ kubeinit_network_name }}"
    groups: 'kubeinit_network'
    network: "{{ kubeinit_network_map['network'] | default(omit) }}"
    gateway_offset: "{{ kubeinit_network_map['gateway_offset'] | default(omit) }}"
    dhcp_start_offset: "{{ kubeinit_network_map['dhcp_start_offset'] | default(omit) }}"
    dhcp_end_offset: "{{ kubeinit_network_map['dhcp_end_offset'] | default(omit) }}"
  when: kubeinit_network_spec is defined

- name: Define kubeinit_network_hostvars and kubeinit_fact_natwork
  ansible.builtin.set_fact:
    kubeinit_network_hostvars: "{{ hostvars[kubeinit_network_name] }}"
    kubeinit_fact_network: "{{ hostvars[kubeinit_network_name].network }}"

- name: Set facts from kubeinit_network group
  ansible.builtin.set_fact:
    kubeinit_cluster_network_name: "{{ kubeinit_network_name }}"
    kubeinit_cluster_network: "{{ kubeinit_fact_network | ansible.utils.ipv4('net') }}"
    kubeinit_cluster_prefix: "{{ kubeinit_fact_network | ansible.utils.ipv4('prefix') }}"
    kubeinit_cluster_netmask: "{{ kubeinit_fact_network | ansible.utils.ipv4('netmask') | ansible.utils.ipv4('address') }}"
    kubeinit_cluster_gateway: "{{ kubeinit_fact_network | ansible.utils.ipv4(kubeinit_network_hostvars.gateway_offset|int) | ansible.utils.ipv4('address') }}"
    kubeinit_cluster_next_available: "{{ kubeinit_fact_network | ansible.utils.ipv4(kubeinit_network_hostvars.dhcp_start_offset|int) | ansible.utils.ipv4('address') }}"
    kubeinit_cluster_last_available: "{{ kubeinit_fact_network | ansible.utils.ipv4(kubeinit_network_hostvars.dhcp_end_offset|int) | ansible.utils.ipv4('address') }}"

- name: Assert additional constraints
  ansible.builtin.assert:
    that:
      - kubeinit_cluster_prefix|int < 30

- name: Add cluster network facts to cluster facts
  ansible.builtin.add_host:
    name: "{{ kubeinit_cluster_name }}"
    network_name: "{{ kubeinit_cluster_network_name }}"
    network: "{{ kubeinit_cluster_network }}"
    prefix: "{{ kubeinit_cluster_prefix }}"
    netmask: "{{ kubeinit_cluster_netmask }}"
    gateway: "{{ kubeinit_cluster_gateway }}"

- name: Assign controller_nodes addresses
  ansible.builtin.add_host:
    name: "{{ controller_node }}"
    group: ['controller_nodes', 'cluster_nodes']
    ansible_connection: 'ssh'
    ansible_host: "{{ kubeinit_cluster_next_available | ansible.utils.ipmath(ansible_loop.index0) | ansible.utils.ipv4('address') }}"
    type: 'virtual'
  loop: "{{ range(kubeinit_spec_controller_count|int) | list }}"
  loop_control:
    extended: true
  vars:
    controller_node: "{{ hostvars[kubeinit_cluster_name].controller_name_pattern | format(ansible_loop.index) }}"

- name: Update next available address for allocation
  ansible.builtin.set_fact:
    kubeinit_cluster_next_available: "{{ kubeinit_cluster_next_available | ansible.utils.ipmath(kubeinit_spec_controller_count|int) }}"

- name: Assign compute_nodes addresses
  ansible.builtin.add_host:
    name: "{{ compute_node }}"
    group: ['compute_nodes', 'cluster_nodes']
    ansible_connection: 'ssh'
    ansible_host: "{{ kubeinit_cluster_next_available | ansible.utils.ipmath(ansible_loop.index0) | ansible.utils.ipv4('address') }}"
    type: 'virtual'
  loop: "{{ range(kubeinit_spec_compute_count|int) | list }}"
  loop_control:
    extended: true
  vars:
    compute_node: "{{ hostvars[kubeinit_cluster_name].compute_name_pattern | format(ansible_loop.index) }}"

- name: Update next available address for allocation
  ansible.builtin.set_fact:
    kubeinit_cluster_next_available: "{{ kubeinit_cluster_next_available | ansible.utils.ipmath(kubeinit_spec_compute_count|int) }}"

- name: Set extra_nodes_map_list fact to defaults
  ansible.builtin.set_fact:
    extra_nodes_map_list: "{{ hostvars['kubeinit-defaults'].default_extra_nodes_map_list }}"

- name: Add entries from extra_nodes_spec to extra_nodes_map_list when defined
  ansible.builtin.set_fact:
    extra_nodes_map_list: "{{ extra_nodes_map_list + (extra_nodes_spec | from_yaml) }}"
  when: extra_nodes_spec is defined

- name: Add extra_nodes entries for the current distro only
  ansible.builtin.add_host:
    name: "{{ item['name'] }}"
    group: 'extra_nodes'
    when_distro: "{{ item['when_distro'] | default(omit) }}"
  loop: "{{ extra_nodes_map_list }}"
  when: (item['when_distro'] is not defined or kubeinit_cluster_distro in item['when_distro']) and item['name'] is defined

- name: Set fact for the number of extra nodes in this cluster
  ansible.builtin.set_fact:
    kubeinit_spec_extra_count: "{{ groups['extra_nodes'] | default([]) | length | int }}"

- name: Assign extra_nodes addresses
  ansible.builtin.add_host:
    name: "{{ extra_node }}"
    group: 'extra_nodes'
    ansible_connection: 'ssh'
    ansible_host: "{{ kubeinit_cluster_next_available | ansible.utils.ipmath(ansible_loop.index0) | ansible.utils.ipv4('address') }}"
    type: 'virtual'
  loop: "{{ groups['extra_nodes'] | default([]) }}"
  loop_control:
    loop_var: extra_node
    extended: true

- name: Update next available address for allocation
  ansible.builtin.set_fact:
    kubeinit_cluster_next_available: "{{ kubeinit_cluster_next_available | ansible.utils.ipmath(kubeinit_spec_extra_count|int) }}"
  when: kubeinit_spec_extra_count|int > 0

- name: Set service_nodes_map_list fact to defaults
  ansible.builtin.set_fact:
    service_nodes_map_list: "{{ hostvars['kubeinit-defaults'].default_service_nodes_map_list }}"

- name: Add entries from service_nodes_spec to service_nodes_map_list when defined
  ansible.builtin.set_fact:
    service_nodes_map_list: "{{ service_nodes_map_list + (service_nodes_spec | from_yaml) }}"
  when: service_nodes_spec is defined

- name: Add service_nodes entries for the current distro only
  ansible.builtin.add_host:
    name: "{{ item['name'] }}"
    group: 'service_nodes'
    when_distro: "{{ item['when_distro'] | default(omit) }}"
  loop: "{{ service_nodes_map_list }}"
  when: (item['when_distro'] is not defined or kubeinit_cluster_distro in item['when_distro']) and item['name'] is defined

- name: Set fact for the number of service nodes in this cluster
  ansible.builtin.set_fact:
    kubeinit_spec_service_count: "{{ groups['service_nodes'] | length | int }}"

- name: Assign service_nodes addresses
  ansible.builtin.add_host:
    name: "{{ service_node }}"
    group: 'service_nodes'
    ansible_connection: 'ssh'
    ansible_host: "{{ kubeinit_cluster_last_available | ansible.utils.ipmath(0 - ansible_loop.index0) | ansible.utils.ipv4('address') }}"
    type: 'container'
  loop: "{{ groups['service_nodes'] }}"
  loop_control:
    loop_var: service_node
    extended: true

- name: Update last available address for allocation
  ansible.builtin.set_fact:
    kubeinit_cluster_last_available: "{{ kubeinit_cluster_last_available | ansible.utils.ipmath(0 - (kubeinit_spec_service_count|int)) }}"

- name: Set cluster dhcp facts
  ansible.builtin.set_fact:
    kubeinit_cluster_dhcp_start: "{{ kubeinit_cluster_next_available | ansible.utils.ipv4('address') }}"
    kubeinit_cluster_dhcp_end: "{{ kubeinit_cluster_last_available | ansible.utils.ipv4('address') }}"

- name: Set cluster dhcp range size
  ansible.builtin.set_fact:
    kubeinit_cluster_dhcp_count: "{{ (kubeinit_cluster_dhcp_end | ansible.utils.ipv4('int') | int) - (kubeinit_cluster_dhcp_start | ansible.utils.ipv4('int') | int) + 1 }}"

- name: Assert sufficient dhcp range
  ansible.builtin.assert:
    that:
      - kubeinit_cluster_dhcp_count|int > 0

- name: Assign dhcp facts
  ansible.builtin.add_host:
    name: "{{ kubeinit_cluster_name }}"
    dhcp_start: "{{ kubeinit_cluster_dhcp_start }}"
    dhcp_end: "{{ kubeinit_cluster_dhcp_end }}"

- name: Clear kubeinit_network_hostvars
  ansible.builtin.set_fact:
    kubeinit_network_hostvars: null

- name: Set cluster_nodes_map_list fact to defaults
  ansible.builtin.set_fact:
    cluster_nodes_map_list: "{{ hostvars['kubeinit-defaults'].default_cluster_nodes_map_list }}"

- name: Add entries from cluster_nodes_spec to cluster_nodes_map_list when defined
  ansible.builtin.set_fact:
    cluster_nodes_map_list: "{{ cluster_nodes_map_list + (cluster_nodes_spec | from_yaml) }}"
  when: cluster_nodes_spec is defined

- name: Add all items in cluster_nodes_map_list to cluster_nodes_defaults for this distro
  ansible.builtin.set_fact:
    cluster_nodes_defaults: "{{ cluster_nodes_defaults | default([]) + (groups['cluster_nodes'] | product([item])) }}"
  loop: "{{ cluster_nodes_map_list }}"
  when: item['when_distro'] is not defined or kubeinit_cluster_distro in item['when_distro']

- name: Apply defaults to all cluster nodes
  ansible.builtin.add_host:
    name: "{{ _host }}"
    os: "{{ _defaults['os'] if (_defaults['os'] is defined and _group_matches|bool and _type_matches|bool) else omit }}"
    vcpus: "{{ _defaults['vcpus'] if (_defaults['vcpus'] is defined and _group_matches|bool and _type_matches|bool) else omit }}"
    maxvcpus: "{{ _defaults['maxvcpus'] if (_defaults['maxvcpus'] is defined and _group_matches|bool and _type_matches|bool) else omit }}"
    disk: "{{ _defaults['disk'] if (_defaults['disk'] is defined and _group_matches|bool and _type_matches|bool) else omit }}"
    ram: "{{ _defaults['ram'] if (_defaults['ram'] is defined and _group_matches|bool and _type_matches|bool) else omit }}"
    target_order: "{{ _defaults['target_order'] if (_defaults['target_order'] is defined and _group_matches|bool and _type_matches|bool) else omit }}"
  loop: "{{ cluster_nodes_defaults }}"
  vars:
    _host: "{{ item[0] }}"
    _defaults: "{{ item[1] }}"
    _group_matches: "{{ item[1]['when_group'] | default('cluster_nodes') in hostvars[item[0]].group_names }}"
    _type_matches: "{{ item[1]['when_type'] | default(hostvars[item[0]].type) | default('') == hostvars[item[0]].type | default('') }}"

- name: Clear cluster_nodes_defaults
  ansible.builtin.set_fact:
    cluster_nodes_defaults: null

- name: Add extra_nodes_map_list to config for current distro only
  ansible.builtin.set_fact:
    extra_nodes_config: "{{ extra_nodes_config | default([]) + (groups['extra_nodes'] | default([]) | product([item])) }}"
  loop: "{{ extra_nodes_map_list }}"
  when: item['when_distro'] is not defined or kubeinit_cluster_distro in item['when_distro']

- name: Apply config to all extra nodes
  ansible.builtin.add_host:
    name: "{{ _host }}"
    os: "{{ _config['os'] if (_config['os'] is defined and _type_matches|bool) else omit }}"
    vcpus: "{{ _config['vcpus'] if (_config['vcpus'] is defined and _type_matches|bool) else omit }}"
    maxvcpus: "{{ _config['maxvcpus'] if (_config['maxvcpus'] is defined and _type_matches|bool) else omit }}"
    disk: "{{ _config['disk'] if (_config['disk'] is defined and _type_matches|bool) else omit }}"
    ram: "{{ _config['ram'] if (_config['ram'] is defined and _type_matches|bool) else omit }}"
    target_order: "{{ _config['target_order'] if (_config['target_order'] is defined and _type_matches|bool) else omit }}"
  loop: "{{ extra_nodes_config }}"
  vars:
    _host: "{{ item[0] }}"
    _config: "{{ item[1] }}"
    _type_matches: "{{ item[1]['when_type'] | default(hostvars[item[0]].type) | default('') == hostvars[item[0]].type | default('') }}"
  when: _config['name'] | default(_host) == _host

- name: Add service_nodes_map_list to config for current distro only
  ansible.builtin.set_fact:
    service_nodes_config: "{{ service_nodes_config | default([]) + (groups['service_nodes'] | product([item])) }}"
  loop: "{{ service_nodes_map_list }}"
  when: item['when_distro'] is not defined or kubeinit_cluster_distro in item['when_distro']

- name: Apply config to all service nodes
  ansible.builtin.add_host:
    name: "{{ _host }}"
    os: "{{ _config['os'] if (_config['os'] is defined) else omit }}"
    services: "{{ _config['services'] if (_config['services'] is defined) else omit }}"
    target_order: "{{ _config['target_order'] if (_config['target_order'] is defined) else omit }}"
  loop: "{{ service_nodes_config }}"
  vars:
    _host: "{{ item[0] }}"
    _config: "{{ item[1] }}"
  when: _config['name'] | default(_host) == _host

- name: Define kubeinit_facts_hostvars
  ansible.builtin.set_fact:
    kubeinit_facts_hostvars: "{{ hostvars['kubeinit-facts'] }}"

- name: Define kubeinit_ssh_keytype
  ansible.builtin.set_fact:
    kubeinit_ssh_keytype: "{{ hostvars['kubeinit-env'].ssh_keytype }}"

- name: Use cluster name as random number seed
  ansible.builtin.set_fact:
    _random_mac: "{{ '52:54:00' | community.general.random_mac(seed=kubeinit_cluster_name) }}"
    _random_uuid: "{{ 999999 | random(seed=kubeinit_cluster_name) | to_uuid }}"

- name: Assign remaining controller_nodes facts
  ansible.builtin.add_host:
    name: "{{ controller_node }}"
    group: ['controller_nodes', 'cluster_nodes']
    mac: "{{ hostvars[controller_node].mac | default('52:54:00' | community.general.random_mac) }}"
    interfaceid: "{{ hostvars[controller_node].interfaceid | default(999999 | random | to_uuid) }}"
  loop: "{{ range(kubeinit_spec_controller_count|int) | list }}"
  loop_control:
    extended: true
  vars:
    controller_node: "{{ hostvars[kubeinit_cluster_name].controller_name_pattern | format(ansible_loop.index) }}"

- name: Assign remaining compute_nodes facts
  ansible.builtin.add_host:
    name: "{{ compute_node }}"
    group: ['compute_nodes', 'cluster_nodes']
    mac: "{{ hostvars[compute_node].mac | default('52:54:00' | community.general.random_mac) }}"
    interfaceid: "{{ hostvars[compute_node].interfaceid | default(999999 | random | to_uuid) }}"
  loop: "{{ range(kubeinit_spec_compute_count|int) | list }}"
  loop_control:
    extended: true
  vars:
    compute_node: "{{ hostvars[kubeinit_cluster_name].compute_name_pattern | format(ansible_loop.index) }}"

- name: Assign remaining extra_nodes facts
  ansible.builtin.add_host:
    name: "{{ hostvars[extra_node].inventory_hostname }}"
    group: 'extra_nodes'
    mac: "{{ hostvars[extra_node].mac | default('52:54:00' | community.general.random_mac) }}"
    interfaceid: "{{ hostvars[extra_node].interfaceid | default(999999 | random | to_uuid) }}"
  loop: "{{ groups['extra_nodes'] | default([]) }}"
  loop_control:
    loop_var: extra_node
    extended: true

- name: Assign remaining service_nodes facts
  ansible.builtin.add_host:
    name: "{{ hostvars[service_node].inventory_hostname }}"
    group: 'service_nodes'
    mac: "{{ hostvars[service_node].mac | default('52:54:00' | community.general.random_mac) }}"
    interfaceid: "{{ hostvars[service_node].interfaceid | default(999999 | random | to_uuid) }}"
  loop: "{{ groups['service_nodes'] | default([]) }}"
  loop_control:
    loop_var: service_node
    extended: true

- name: Set additional kubeinit-env facts
  ansible.builtin.set_fact:
    kubeinit_dns_public: "{{ hostvars['kubeinit-env'].dns_public }}"

- name: Set libvirt release facts
  ansible.builtin.set_fact:
    kubeinit_libvirt_debian_release: "11"
    # It is possible to configure different versions of the OS depending on the distribution
    # kubeinit_libvirt_ubuntu_release: "{{ 'focal' if (kubeinit_cluster_distro == 'cdk') else 'jammy' }}"
    kubeinit_libvirt_ubuntu_release: "jammy"

- name: Set registry authentication facts
  ansible.builtin.set_fact:
    kubeinit_registry_user: registryusername
    kubeinit_registry_password: registrypassword

- name: Determine the hypervisor target for all inventory nodes
  ansible.builtin.set_fact:
    node_targets: "{{ (node_targets | default([])) | union([inventory_node] | product(hostvars[inventory_node].target_order | reverse)) }}"
  loop: "{{ groups['cluster_nodes'] + (groups['extra_nodes'] | default([])) + groups['service_nodes'] }}"
  loop_control:
    loop_var: inventory_node

- name: Assign the first requested hypervisor available for each node
  ansible.builtin.add_host:
    name: "{{ inventory_node }}"
    target: "{{ hostvars[inventory_node].target | default(candidate) }}"
  loop: "{{ node_targets }}"
  vars:
    inventory_node: "{{ item[0] }}"
    candidate: "{{ item[1] }}"
  when: candidate in groups['kubeinit_hypervisors']

- name: Update hosts and stop the deployment if required
  block:
    - name: Add tasks-gather-facts to tasks completed
      ansible.builtin.add_host:
        name: "kubeinit-facts"
        tasks_completed: "{{ ['task-gather-facts'] }}"

    - name: Update kubeinit_facts_hostvars
      ansible.builtin.set_fact:
        kubeinit_facts_hostvars: "{{ hostvars['kubeinit-facts'] }}"

    - name: Stop the deployment if required
      block:
        - name: Stop after 'task-gather-facts' when requested
          ansible.builtin.add_host:
            name: "kubeinit-facts"
            playbook_terminated: true
        - name: End play
          ansible.builtin.meta: end_play
      when: kubeinit_stop_after_task is defined and kubeinit_stop_after_task in hostvars['kubeinit-facts'].tasks_completed
  tags: omit_from_grapher