---
- name: Set contrail_masters var
  set_fact:
    contrail_masters: ""

- name: Set contrail_masters from contrail_control_data_interface
  set_fact:
    contrail_masters: "{{ contrail_control_data_interface }}"
  when:
    - contrail_control_data_interface is defined

- name: Set contrail_masters from infra nodes
  set_fact:
    contrail_masters: "{{ contrail_masters }} {{ item }}"
  when:
    - contrail_control_data_interface is not defined
    - hostvars[item]['openshift_node_labels'] is defined
    - hostvars[item]['openshift_node_labels']['region'] is defined
    - hostvars[item]['openshift_node_labels']['region'] == 'infra'
  with_items: "{{ groups.nodes }}"

- name: Set contrail_masters from masters group if not set before
  set_fact:
    contrail_masters: "{{ contrail_masters }} {{ item }}"
  with_items: "{{ groups.masters }}"
  when: contrail_masters.split() | length < 1
