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 01:32:07 +0000 00:11:17.00 nyctea root Ansible 2.15.2 ara 1.6.1 (client), 1.6.1 (server) Python 3.11.4 6 9 738 805 43 1

File: /root/.ansible/collections/ansible_collections/kubeinit/kubeinit/roles/kubeinit_libvirt/tasks/create_network.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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
---
# 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.

- name: Clean hypervisors and stop if required
  block:
    - name: Cleanup hypervisors if needed
      ansible.builtin.include_role:
        name: kubeinit.kubeinit.kubeinit_libvirt
        tasks_from: cleanup_hypervisors.yml
        public: true
      vars:
        hypervisors_cleaned: "{{ 'kubeinit_facts' in groups }}"
      when: not hypervisors_cleaned

    - name: Stop the deployment
      block:
        - name: "Stop before 'task-create-network' when requested"
          ansible.builtin.add_host:
            name: "kubeinit-facts"
            playbook_terminated: true
        - name: End play
          ansible.builtin.meta: end_play
      when: kubeinit_stop_before_task is defined and kubeinit_stop_before_task == 'task-create-network'
  tags: omit_from_grapher

#
# Configure OVN on all the HVs
#

#
# We install all OVN requirements in the ovn-central host
#
- name: Install OVN central packages in CentOS/RHEL
  ansible.builtin.shell: |
    dnf install -y centos-release-nfv-openvswitch
    dnf install -y openvswitch2.16 \
                   ovn-2021 \
                   ovn-2021-central \
                   ovn-2021-host
  args:
    executable: /bin/bash
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_ovn_central_host }}"
  when: hostvars[kubeinit_ovn_central_host].distribution_family == 'CentOS'

- name: Install OVN central packages in Fedora
  ansible.builtin.command: |
    dnf install -y openvswitch \
                   ovn \
                   ovn-central \
                   ovn-host
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_ovn_central_host }}"
  when: hostvars[kubeinit_ovn_central_host].distribution_family == 'Fedora'

- name: Install OVN central packages in Ubuntu/Debian
  ansible.builtin.command: |
    apt-get install -y openvswitch-common \
                       openvswitch-switch \
                       ovn-common \
                       ovn-host \
                       ovn-central
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_ovn_central_host }}"
  when: hostvars[kubeinit_ovn_central_host].distribution_family == 'Debian'

#
# We DO NOT install ovn-central (OVN requirement) in the other hypervisors
#
- name: Collect all HVs which are not the ovn-central host
  ansible.builtin.set_fact:
    kubeinit_other_ovn_hosts: "{{ (kubeinit_other_ovn_hosts | default([])) + [ovn_host] }}"
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  when: ovn_host not in kubeinit_ovn_central_host

- name: Install OVN host packages in CentOS/RHEL
  ansible.builtin.shell: |
    dnf install -y centos-release-nfv-openvswitch
    dnf install -y openvswitch2.16 \
                   ovn-2021 \
                   ovn-2021-host
  args:
    executable: /bin/bash
  register: _result
  changed_when: "_result.rc == 0"
  loop: "{{ kubeinit_other_ovn_hosts | default([]) }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: hostvars[ovn_host].distribution_family == 'CentOS'

- name: Install OVN host packages in Fedora
  ansible.builtin.command: |
    dnf install -y openvswitch \
                   ovn \
                   ovn-host
  register: _result
  changed_when: "_result.rc == 0"
  loop: "{{ kubeinit_other_ovn_hosts | default([]) }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: hostvars[ovn_host].distribution_family == 'Fedora'

- name: Install OVN host packages in Ubuntu/Debian
  ansible.builtin.command: |
    apt-get install -y openvswitch-common \
                       openvswitch-switch \
                       ovn-common \
                       ovn-host
  register: _result
  changed_when: "_result.rc == 0"
  loop: "{{ kubeinit_other_ovn_hosts | default([]) }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: hostvars[ovn_host].distribution_family == 'Debian'

#
# Configure firewalld as needed
#
- name: Gather current firewalld rules for ovn hosts
  ansible.posix.firewalld_info:
    active_zones: true
  register: _result_firewalld_info
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: hostvars[ovn_host].firewalld_is_active

- name: Set fact for expected rich_rule result
  ansible.builtin.set_fact:
    rich_rule_result: "rule family=\"ipv4\" source address=\"{{ kubeinit_cluster_network }}\" masquerade"

- name: Check firewalld services and rich_rules for existing entries
  ansible.builtin.add_host:
    name: "{{ item.ovn_host }}"
    add_ovn_rich_rule: "{{ true if (rich_rule_result not in default_zone_info.rich_rules) else false }}"
    add_ovn_central_service: "{{ true if ('ovn-central-firewall-service' not in default_zone_info.services) else false }}"
    add_ovn_host_service: "{{ true if ('ovn-host-firewall-service' not in default_zone_info.services) else false }}"
    reload_firewalld: "{{ true if ('ovn-host-firewall-service' not in default_zone_info.services) else false }}"
  loop: "{{ _result_firewalld_info.results }}"
  vars:
    default_zone_info: "{{ item.firewalld_info.zones[item.firewalld_info.default_zone] }}"
  when: item.firewalld_info is defined

- name: Refresh firewalld services list to pick up ovn services
  ansible.builtin.command: |
    firewall-cmd --reload
  register: _result
  changed_when: "_result.rc == 0"
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: hostvars[ovn_host].reload_firewalld | default(false)

- name: Enable OVN central in firewalld
  ansible.posix.firewalld:
    service: ovn-central-firewall-service
    permanent: true
    state: enabled
    immediate: true
  delegate_to: "{{ kubeinit_ovn_central_host }}"
  when: hostvars[kubeinit_ovn_central_host].add_ovn_central_service | default(false)

- name: Enable OVN NAT in firewalld
  ansible.posix.firewalld:
    rich_rule: "rule family=ipv4 source address={{ kubeinit_cluster_network }} masquerade"
    permanent: true
    state: enabled
    immediate: true
  delegate_to: "{{ kubeinit_ovn_central_host }}"
  when: hostvars[kubeinit_ovn_central_host].add_ovn_rich_rule | default(false)

- name: Enable OVN host in firewalld
  ansible.posix.firewalld:
    service: ovn-host-firewall-service
    permanent: true
    state: enabled
    immediate: true
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: hostvars[ovn_host].add_ovn_host_service | default(false)

- name: Refresh firewalld services list
  ansible.builtin.command: |
    firewall-cmd --reload
  register: _result
  changed_when: "_result.rc == 0"
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: hostvars[ovn_host].reload_firewalld | default(false)

- name: Reload podman networks
  ansible.builtin.command: |
    podman network reload --all
  register: _result
  changed_when: "_result.rc == 0"
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: hostvars[ovn_host].reload_firewalld | default(false) and hostvars[ovn_host].podman_is_installed | default(false)

- name: Only restart if this is the only cluster network
  block:

    - name: Enable and start OVN services in the ovn-central hypervisor (CentOS based)
      ansible.builtin.service:
        name: "{{ item }}"
        state: started
        enabled: yes
      loop:
        - openvswitch
        - ovn-northd
        - ovn-controller
      delegate_to: "{{ kubeinit_ovn_central_host }}"
      when: hostvars[kubeinit_ovn_central_host].distribution_family != 'Debian'

    - name: Enable and start OVN services in the rest of the hypervisors (CentOS based)
      ansible.builtin.service:
        name: "{{ service_name }}"
        state: started
        enabled: yes
      loop: "{{ kubeinit_other_ovn_hosts | default([]) | product(['openvswitch', 'ovn-controller']) }}"
      vars:
        ovn_host: "{{ item[0] }}"
        service_name: "{{ item[1] }}"
      delegate_to: "{{ ovn_host }}"
      when: hostvars[ovn_host].distribution_family != 'Debian'

    - name: Enable and start OVN services in the ovn-central hypervisor (Debian/Ubuntu based)
      ansible.builtin.service:
        name: "{{ item }}"
        state: started
        enabled: yes
      loop:
        - openvswitch-switch
        - ovn-host
        - ovn-central
      delegate_to: "{{ kubeinit_ovn_central_host }}"
      when: hostvars[kubeinit_ovn_central_host].distribution_family == 'Debian'

    - name: Enable and start OVN services in the rest of the hypervisors (Debian/Ubuntu based)
      ansible.builtin.service:
        name: "{{ service_name }}"
        state: started
        enabled: yes
      loop: "{{ kubeinit_other_ovn_hosts | default([]) | product(['openvswitch-switch', 'ovn-host']) }}"
      vars:
        ovn_host: "{{ item[0] }}"
        service_name: "{{ item[1] }}"
      delegate_to: "{{ ovn_host }}"
      when: hostvars[ovn_host].distribution_family == 'Debian'

    - name: Wait until OVN services are running
      ansible.builtin.command: /usr/share/ovn/scripts/ovn-ctl status_northd
      register: _result
      changed_when: "_result.rc == 0"
      retries: 6
      delay: 10
      delegate_to: "{{ kubeinit_ovn_central_host }}"
      until: "'ovn-northd is running' in _result.stdout"

  when: kubeinit_destroy_ovn_network

- name: Wait for changes to propagate
  ansible.builtin.command: |
    /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 sync
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_ovn_central_host }}"

- name: Configure OVS on the Hypervisors
  ansible.builtin.shell: |
    CENTRAL_IP={{ hostvars[kubeinit_ovn_central_host].ssh_connection_address }} # This is the IP of the ovn-central HV
    LOCAL_IP={{ hostvars[ovn_host].ssh_connection_address }} # This is the IP of the current HV
    ENCAP_TYPE={{ kubeinit_libvirt_ovn_encapsulation }}
    /usr/bin/ovs-vsctl set Open_vSwitch . \
        external_ids:ovn-remote="tcp:$CENTRAL_IP:{{ kubeinit_libvirt_ovn_southbound_port }}" \
        external_ids:ovn-nb="tcp:$CENTRAL_IP:{{ kubeinit_libvirt_ovn_northbound_port }}" \
        external_ids:ovn-encap-ip=$LOCAL_IP \
        external_ids:ovn-encap-type="$ENCAP_TYPE" \
        external_ids:system-id="{{ ovn_host }}"
    # On each HV lets create a virtual bridge br-int
    # This bridge will be used when we create the VMs
    /usr/bin/ovs-vsctl --may-exist add-br br-int
  args:
    executable: /bin/bash
  register: _result
  changed_when: "_result.rc == 0"
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"
  when: kubeinit_destroy_ovn_network

- name: Wait for changes to propagate
  ansible.builtin.command: |
    /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 sync
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_ovn_central_host }}"

#
# OVN post deployment configuration steps.
#
- name: Delegate to kubeinit_ovn_central_host
  block:

    - name: Configure OVN in the ovn-central hypervisor
      ansible.builtin.shell: |
        # Below two commands only for central. For SSL, other steps are required.
        /usr/bin/ovn-nbctl set-connection ptcp:{{ kubeinit_libvirt_ovn_northbound_port }}
        /usr/bin/ovn-sbctl set-connection ptcp:{{ kubeinit_libvirt_ovn_southbound_port }}
      args:
        executable: /bin/bash
      register: _result
      changed_when: "_result.rc == 0"
      when: kubeinit_destroy_ovn_network

    - name: Wait for changes to propagate
      ansible.builtin.command: |
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 sync
      register: _result
      changed_when: "_result.rc == 0"

    #
    # We create the OVN switch that will be bound to each chassis (hypervisor)
    # In this switch we will create a port per guest
    #
    - name: Remove and create the cluster switch if exists
      ansible.builtin.shell: |
        #
        # Create a logical switch
        #
        /usr/bin/ovn-nbctl ls-del sw-{{ kubeinit_cluster_name }}
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 ls-add sw-{{ kubeinit_cluster_name }}
      args:
        executable: /bin/bash
      register: _result
      changed_when: "_result.rc == 0"

    - name: Wait for changes to propagate
      ansible.builtin.command: |
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 sync
      register: _result
      changed_when: "_result.rc == 0"

    - name: Create OVS/OVN bindings for the VMs ports
      ansible.builtin.shell: |
        #
        # We create an OVN port using the interface ID and the mac address of the VM
        #
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 lsp-add sw-{{ kubeinit_cluster_name }} {{ hostvars[item].interfaceid }}
        #
        # The port name is the interface id of the VM, now we assign the mac address of the VM to the port
        #
        /usr/bin/ovn-nbctl --wait=sb --wait=sb --timeout=30 lsp-set-addresses {{ hostvars[item].interfaceid }} "{{ hostvars[item].mac }} {{ hostvars[item].ansible_host }}"
        /usr/bin/ovn-nbctl --wait=sb --wait=sb --timeout=30 lsp-set-port-security {{ hostvars[item].interfaceid }} "{{ hostvars[item].mac }} {{ hostvars[item].ansible_host }}"
      args:
        executable: /bin/bash
      loop: "{{ groups['all_nodes'] }}"
      register: _result
      changed_when: "_result.rc == 0"

    - name: Wait for changes to propagate
      ansible.builtin.command: |
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 sync
      register: _result
      changed_when: "_result.rc == 0"

    - name: Configuring a router connected to the guests switch
      ansible.builtin.shell: |
        #
        # Create a logical router to connect the VMs switch
        #
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 lr-add lr0
        #
        # We create the external access switch
        #
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 ls-add public
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 lrp-add lr0 lr0-public {{ '00:00:20' | community.general.random_mac }} 172.16.0.1/24
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 lsp-add public public-lr0
        /usr/bin/ovn-nbctl lsp-set-type public-lr0 router
        /usr/bin/ovn-nbctl lsp-set-addresses public-lr0 router
        /usr/bin/ovn-nbctl lsp-set-options public-lr0 router-port=lr0-public
        #
        # Create a localnet port
        #
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 lsp-add public public-ln
        /usr/bin/ovn-nbctl lsp-set-type public-ln localnet
        /usr/bin/ovn-nbctl lsp-set-addresses public-ln unknown
        /usr/bin/ovn-nbctl lsp-set-options public-ln network_name=provider
        #
        # We add a bridge mapping from br-ex called provider
        #
        /usr/bin/ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=provider:br-ex
        #
        # Configuring the chassis gateway to the ovn-central hypervisor
        #
        /usr/bin/ovn-nbctl lrp-set-gateway-chassis lr0-public {{ kubeinit_ovn_central_host }}
        /usr/bin/ovn-nbctl \
          --id=@gc0 create Gateway_Chassis name=lr0-public chassis_name={{ kubeinit_ovn_central_host }} priority=20 -- \
          set Logical_Router_Port lr0-public 'gateway_chassis=[@gc0]'
        /usr/bin/ovn-nbctl set logical_router_port lr0-public options:redirect-chassis={{ kubeinit_ovn_central_host }}
        #
        # Create an ovs br-ex bridge to connect to the host
        #
        /usr/bin/ovs-vsctl --may-exist add-br br-ex
        ip addr add 172.16.0.254/24 dev br-ex
        ip link set br-ex up
        #
        # Routes
        #
        # Connectivity to external/additional networks
        /usr/bin/ovn-nbctl lr-route-add lr0 0.0.0.0/0 172.16.0.254
        #
        # Disable rp_filter
        #
        sysctl net.ipv4.conf.all.rp_filter=2
      args:
        executable: /bin/bash
      register: _result
      changed_when: "_result.rc == 0"
      when: kubeinit_destroy_ovn_network

    - name: Wait for changes to propagate
      ansible.builtin.command: |
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 sync
      register: _result
      changed_when: "_result.rc == 0"

    - name: Attach our cluster network to the logical router
      ansible.builtin.shell: |
        #
        # Create a logical router to connect the VMs switch
        #
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 lrp-add lr0 lr0-sw-{{ kubeinit_cluster_name }} {{ '00:00:00' | community.general.random_mac }} {{ kubeinit_cluster_gateway }}/{{ kubeinit_cluster_prefix }}
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 lsp-add sw-{{ kubeinit_cluster_name }} sw-{{ kubeinit_cluster_name }}-lr0
        /usr/bin/ovn-nbctl lsp-set-type sw-{{ kubeinit_cluster_name }}-lr0 router
        /usr/bin/ovn-nbctl lsp-set-addresses sw-{{ kubeinit_cluster_name }}-lr0 router
        /usr/bin/ovn-nbctl lsp-set-options sw-{{ kubeinit_cluster_name }}-lr0 router-port=lr0-sw-{{ kubeinit_cluster_name }}
        #
        # Routes
        #
        # Connectivity from the host to the guest machines
        ip route add {{ kubeinit_cluster_network }} via 172.16.0.1 dev br-ex
      args:
        executable: /bin/bash
      register: _result
      changed_when: "_result.rc == 0"

    - name: Wait for changes to propagate
      ansible.builtin.command: |
        /usr/bin/ovn-nbctl --wait=hv --wait=sb --timeout=30 sync
      register: _result
      changed_when: "_result.rc == 0"

    #
    # The NAT rules are mandatory to allow guests to have external connectivity
    # there might be cases where they are not needed, but this change needs testing
    # ----------- THESE ARE REQUIRED AT LEAST IN DEBIAN AND FEDORA CHASSIS -----------
    #
    - name: Configuring NAT
      ansible.builtin.shell: |
        set -eo pipefail
        #
        # NAT from the external interface
        #
        # Get the external interface name
        iface=$(ip route get "8.8.8.8" | grep -Po '(?<=(dev )).*(?= src| proto)')
        #
        iptables -t nat -A POSTROUTING -s {{ kubeinit_cluster_network }} -o $iface -j MASQUERADE
        #
        iptables -A FORWARD -i $iface -j ACCEPT
        iptables -A FORWARD -i br-ex -j ACCEPT
        iptables -A FORWARD -o $iface -j ACCEPT
        iptables -A FORWARD -o br-ex -j ACCEPT
        #
        iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
        #
        iptables -P FORWARD ACCEPT
        iptables -P INPUT ACCEPT
        iptables -P OUTPUT ACCEPT
      args:
        executable: /bin/bash
      register: _result
      changed_when: "_result.rc == 0"
      when: not hostvars[kubeinit_ovn_central_host].firewalld_is_active

  delegate_to: "{{ kubeinit_ovn_central_host }}"

#
# Define libvirt common resources and networks
#
- name: Render KubeInit networks for debugging
  ansible.builtin.template:
    src: cluster-net.xml.j2
    dest: "{{ kubeinit_libvirt_hypervisor_tmp_dir }}/cluster-net.xml"
    mode: '0644'
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"

- name: Define KubeInit networks
  community.libvirt.virt_net:
    command: define
    name: "{{ kubeinit_cluster_network_name }}"
    xml: '{{ lookup("template", "cluster-net.xml.j2") }}'
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"

- name: Activate KubeInit networks
  community.libvirt.virt_net:
    state: active
    name: "{{ kubeinit_cluster_network_name }}"
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"

- name: Autostart KubeInit networks
  community.libvirt.virt_net:
    autostart: yes
    name: "{{ kubeinit_cluster_network_name }}"
  loop: "{{ groups['all_ovn_hosts'] }}"
  loop_control:
    loop_var: ovn_host
  delegate_to: "{{ ovn_host }}"

- name: Show northbound status
  ansible.builtin.command: /usr/bin/ovn-nbctl show
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_ovn_central_host }}"

- name: Show southbound status
  ansible.builtin.command: /usr/bin/ovn-sbctl show
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_ovn_central_host }}"

- name: Show openvswitch status
  ansible.builtin.command: /usr/bin/ovs-vsctl show
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_ovn_central_host }}"

- name: Add hosts and stop if required
  block:
    - name: Add task-create-network to tasks_completed
      ansible.builtin.add_host:
        name: "kubeinit-facts"
        tasks_completed: "{{ kubeinit_facts_hostvars.tasks_completed | union(['task-create-network']) }}"

    - 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-create-network' 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 kubeinit_facts_hostvars.tasks_completed
  tags: omit_from_grapher