---
- name: Ensure NetworkManager is disabled
  service:
    name: NetworkManager
    state: stopped
    enabled: no
  become: True
  register: nm_result
  failed_when:
    - nm_result is failed
    # Ugh, Ansible's service module doesn't handle uninstalled services.
    - "'Could not find the requested service' not in nm_result.msg"
  when: ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version == "8"

- import_role:
    name: ahuffman.resolv
  when: resolv_is_managed | bool
  become: True

- name: Configure network interfaces (RedHat)
  import_role:
    name: MichaelRigart.interfaces
  vars:
    interfaces_route_tables: "{{ network_route_tables }}"
    interfaces_ether_interfaces: >
      {{ network_interfaces |
         net_select_ethers |
         map('net_interface_obj') |
         list }}
    interfaces_bridge_interfaces: >
      {{ network_interfaces |
         net_select_bridges |
         map('net_bridge_obj') |
         list }}
    interfaces_bond_interfaces: >
      {{ network_interfaces |
         net_select_bonds |
         map('net_bond_obj') |
         list }}
    interfaces_setup_filter: "{{ kayobe_ansible_setup_filter }}"
    interfaces_setup_gather_subset: "{{ kayobe_ansible_setup_gather_subset }}"

# NOTE(priteau): We need to run handlers from MichaelRigart.interfaces before
# we start configuring any veth interfaces.
# NOTE(bbezak): Flush handlers does not support when clause, workaround applied:
# https://github.com/ansible/ansible/issues/77616
# https://github.com/jmnavarrol/ansible-issue-flush-handlers/tree/master#workaround

- name: "flush_handlers"
  include_tasks:
    file: include_flush.yml
  when: ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version == "9"

# Configure virtual ethernet patch links to connect the workload provision
# and external network bridges to the Neutron OVS bridge.
- name: Ensure OVS patch links exist
  import_role:
    name: veth
  vars:
    veth_interfaces: "{{ network_interfaces | net_ovs_veths }}"
  when: "'overcloud' in group_names"
