---
# NOTE(mnasiadka): external_ids:system-id uniquely identifies a physical system, used by OVN and other controllers
- name: Set system-id and hw-offload
  become: true
  kolla_toolbox:
    container_engine: "{{ kolla_container_engine }}"
    user: root
    module_name: openvswitch_db
    module_args:
      table: Open_vSwitch
      record: .
      col: "{{ item.col }}"
      key: "{{ item.name }}"
      value: "{{ item.value }}"
      state: "{{ item.state | default('present') }}"
  loop:
    - { col: "external_ids", name: "system-id", value: "{{ openvswitch_system_id }}" }
    - { col: "other_config", name: "hw-offload", value: true, state: "{{ 'present' if openvswitch_hw_offload | bool else 'absent' }}" }

- name: Ensuring OVS bridge is properly setup
  become: true
  command: "{{ kolla_container_engine }} exec openvswitch_db /usr/local/bin/kolla_ensure_openvswitch_configured {{ item.0 }} {{ item.1 }}"
  register: status
  changed_when: status.stdout.find('changed') != -1
  when:
    - inventory_hostname in groups["network"]
      or (inventory_hostname in groups["compute"] and computes_need_external_bridge | bool )
  with_together:
    - "{{ neutron_bridge_name.split(',') }}"
    - "{{ neutron_external_interface.split(',') }}"
