diff --git a/ansible/roles/bastion-network/tasks/main.yml b/ansible/roles/bastion-network/tasks/main.yml index 4e185930..101ab750 100644 --- a/ansible/roles/bastion-network/tasks/main.yml +++ b/ansible/roles/bastion-network/tasks/main.yml @@ -90,14 +90,6 @@ when: - enable_bond | default(false) block: - - name: Set bastion bond interface names from hardware mapping - set_fact: - bastion_bond0_interface1: "{{ hw_nic_name[lab][machine_type][bond0_port1|int] }}" - bastion_bond0_interface2: "{{ hw_nic_name[lab][machine_type][bond0_port2|int] }}" - when: - - lab in hw_nic_name - - machine_type in hw_nic_name[lab] - - hw_nic_name[lab][machine_type] | length > (bond0_port2|int) - name: Remove existing connections for bond slave interfaces nmcli: @@ -106,7 +98,6 @@ loop: - "{{ bastion_bond0_interface1 }}" - "{{ bastion_bond0_interface2 }}" - ignore_errors: true - name: Create bond0 connection for bastion nmcli: @@ -114,10 +105,9 @@ conn_name: bond0 ifname: bond0 ip4: "{{ bastion_controlplane_ip }}/{{ controlplane_network_prefix }}" + mode: 802.3ad + miimon: 100 state: present - bond: - mode: 802.3ad - miimon: 100 when: bastion_controlplane_ip | ansible.utils.ipv4 - name: Create bond0 connection for bastion (ipv6) @@ -126,10 +116,9 @@ conn_name: bond0 ifname: bond0 ip6: "{{ bastion_controlplane_ip }}/{{ controlplane_network_prefix }}" + mode: 802.3ad + miimon: 100 state: present - bond: - mode: 802.3ad - miimon: 100 when: bastion_controlplane_ip | ansible.utils.ipv6 - name: Add first interface as bond slave diff --git a/ansible/roles/create-inventory/defaults/main/networks.yml b/ansible/roles/create-inventory/defaults/main/networks.yml index 522a8ab1..57d12dc1 100644 --- a/ansible/roles/create-inventory/defaults/main/networks.yml +++ b/ansible/roles/create-inventory/defaults/main/networks.yml @@ -39,5 +39,5 @@ bond0_port2: 2 # The assisted-installer doesn't need exact nic names for the private bond. These names are used # as representatives for the actual nic names, the actual nics are determined by the mac addresses private_bond_interfaces: -- eth0 -- eth1 \ No newline at end of file + - eth0 + - eth1 diff --git a/ansible/roles/create-inventory/tasks/main.yml b/ansible/roles/create-inventory/tasks/main.yml index 0b06589c..2d2c16fe 100644 --- a/ansible/roles/create-inventory/tasks/main.yml +++ b/ansible/roles/create-inventory/tasks/main.yml @@ -120,6 +120,16 @@ - lab in hw_nic_name - machine_type in hw_nic_name[lab] +- name: Auto-configure bastion bond interfaces (only when bonding is enabled) + set_fact: + bastion_bond0_interface1: "{{ hw_nic_name[lab][machine_type][bond0_port1|int] }}" + bastion_bond0_interface2: "{{ hw_nic_name[lab][machine_type][bond0_port2|int] }}" + when: + - enable_bond | default(false) + - lab in hw_nic_name + - machine_type in hw_nic_name[lab] + - hw_nic_name[lab][machine_type] | length > (bond0_port2|int) + - name: Bond configuration for scale/performance labs when: (lab in rh_labs) and enable_bond | default(false) and not (public_vlan | default(false)) block: @@ -198,15 +208,18 @@ block: - name: MNO - Set controlplane0 bond mac addresses set_fact: - controlplane0_bond0_macs: "{{ (controlplane0_foreman_data.json.interfaces | selectattr('name', 'eq', bond0_interface1) | first).mac }},{{ (controlplane0_foreman_data.json.interfaces | selectattr('name', 'eq', bond0_interface2) | first).mac }}" + controlplane0_bond0_macs: >- + {{ ocpinventory.json.nodes[1].mac[bond0_port1|int - 1] ~ ',' ~ ocpinventory.json.nodes[1].mac[bond0_port2|int - 1] }} - name: MNO - Set controlplane1 bond mac addresses set_fact: - controlplane1_bond0_macs: "{{ (controlplane1_foreman_data.json.interfaces | selectattr('name', 'eq', bond0_interface1) | first).mac }},{{ (controlplane1_foreman_data.json.interfaces | selectattr('name', 'eq', bond0_interface2) | first).mac }}" + controlplane1_bond0_macs: >- + {{ ocpinventory.json.nodes[2].mac[bond0_port1|int - 1] ~ ',' ~ ocpinventory.json.nodes[2].mac[bond0_port2|int - 1] }} - name: MNO - Set controlplane2 bond mac addresses set_fact: - controlplane2_bond0_macs: "{{ (controlplane2_foreman_data.json.interfaces | selectattr('name', 'eq', bond0_interface1) | first).mac }},{{ (controlplane2_foreman_data.json.interfaces | selectattr('name', 'eq', bond0_interface2) | first).mac }}" + controlplane2_bond0_macs: >- + {{ ocpinventory.json.nodes[3].mac[bond0_port1|int - 1] ~ ',' ~ ocpinventory.json.nodes[3].mac[bond0_port2|int - 1] }} - name: MNO - Set max number of nodes set_fact: @@ -242,16 +255,16 @@ set_fact: ocpinventory_worker_nodes: >- {{ - ocpinventory_worker_nodes | zip(mno_foreman_data.results) | - map('combine') | - map('combine', { - 'bond0_macs': ((item.1.json.interfaces | selectattr('name', 'eq', bond0_interface1) | first).mac + ',' + (item.1.json.interfaces | selectattr('name', 'eq', bond0_interface2) | first).mac) - }) | - list + ocpinventory_worker_nodes[:idx] + + [ocpinventory_worker_nodes[idx] | combine({ + 'bond0_macs': (item.mac[bond0_port1|int - 1] + ',' + item.mac[bond0_port2|int - 1]) + })] + + ocpinventory_worker_nodes[idx + 1:] }} - loop: "{{ ocpinventory_worker_nodes | zip(mno_foreman_data.results) | list }}" + loop: "{{ ocpinventory_worker_nodes }}" loop_control: loop_var: item + index_var: idx - name: Single Node OpenShift cluster type tasks when: cluster_type == "sno" @@ -296,21 +309,33 @@ when: cluster_type == "sno" and ocpinventory_worker_nodes|length > 0 register: sno_worker_foreman_data + - name: SNO - Auto-configure bond interface names from hardware mapping (when bonding is enabled) + set_fact: + bond0_interface1: "{{ hw_nic_name[lab][machine_type][bond0_port1|int] }}" + bond0_interface2: "{{ hw_nic_name[lab][machine_type][bond0_port2|int] }}" + when: + - enable_bond | default(false) and not (public_vlan | default(false)) + - lab in hw_nic_name + - machine_type in hw_nic_name[lab] + - hw_nic_name[lab][machine_type] | length > (bond0_port2|int) + + + - name: SNO - Add bond MAC addresses to SNO nodes (when bonding is enabled) when: enable_bond | default(false) and not (public_vlan | default(false)) set_fact: ocpinventory_sno_nodes: >- {{ - ocpinventory_sno_nodes | zip(sno_foreman_data.results) | - map('combine') | - map('combine', { - 'bond0_macs': ((item.1.json.interfaces | selectattr('name', 'eq', bond0_interface1) | first).mac + ',' + (item.1.json.interfaces | selectattr('name', 'eq', bond0_interface2) | first).mac) - }) | - list + ocpinventory_sno_nodes[:idx] + + [ocpinventory_sno_nodes[idx] | combine({ + 'bond0_macs': (item.mac[bond0_port1|int - 1 ] + ',' + item.mac[bond0_port2|int - 1]) + })] + + ocpinventory_sno_nodes[idx + 1:] }} - loop: "{{ ocpinventory_sno_nodes | zip(sno_foreman_data.results) | list }}" + loop: "{{ ocpinventory_sno_nodes }}" loop_control: loop_var: item + index_var: idx - name: set json query fact set_fact: diff --git a/ansible/roles/create-inventory/templates/inventory-mno.j2 b/ansible/roles/create-inventory/templates/inventory-mno.j2 index 9b719ee3..d6456e45 100644 --- a/ansible/roles/create-inventory/templates/inventory-mno.j2 +++ b/ansible/roles/create-inventory/templates/inventory-mno.j2 @@ -13,6 +13,10 @@ base_dns_name={{ base_dns_name }} bastion_lab_interface={{ bastion_lab_interface }} bastion_controlplane_interface={{ bastion_controlplane_interface }} controlplane_lab_interface={{ controlplane_lab_interface }} +{% if enable_bond | default(false) %} +bastion_bond0_interface1={{ bastion_bond0_interface1 }} +bastion_bond0_interface2={{ bastion_bond0_interface2 }} +{% endif %} [bastion] {{ bastion_machine }} ansible_ssh_user=root bmc_address=mgmt-{{ bastion_machine }} lab_ip={{ bastion_foreman_data.json.ip }} diff --git a/ansible/roles/create-inventory/templates/inventory-sno.j2 b/ansible/roles/create-inventory/templates/inventory-sno.j2 index 63376c11..200c82c7 100644 --- a/ansible/roles/create-inventory/templates/inventory-sno.j2 +++ b/ansible/roles/create-inventory/templates/inventory-sno.j2 @@ -18,6 +18,10 @@ base_dns_name={{ base_dns_name }} bastion_lab_interface={{ bastion_lab_interface }} bastion_controlplane_interface={{ bastion_controlplane_interface }} controlplane_lab_interface={{ controlplane_lab_interface }} +{% if enable_bond | default(false) %} +bastion_bond0_interface1={{ bastion_bond0_interface1 }} +bastion_bond0_interface2={{ bastion_bond0_interface2 }} +{% endif %} [bastion] {{ bastion_machine }} ansible_ssh_user=root bmc_address=mgmt-{{ bastion_machine }} lab_ip={{ bastion_foreman_data.json.ip }} diff --git a/ansible/roles/wait-hosts-discovered/tasks/set_hostname_role.yml b/ansible/roles/wait-hosts-discovered/tasks/set_hostname_role.yml index 0fe46a95..807b3b11 100644 --- a/ansible/roles/wait-hosts-discovered/tasks/set_hostname_role.yml +++ b/ansible/roles/wait-hosts-discovered/tasks/set_hostname_role.yml @@ -11,15 +11,29 @@ host_id: "{{ discovered_host.id }}" host_macs: "{{ (discovered_host.inventory | from_json) | json_query('interfaces[].mac_address') | lower }}" -- name: Set the hostname and role via mac address +- name: Set the hostname and role via mac address (non-bonded) set_fact: hostname: "{{ item }}" host_role: "{{ hostvars[item]['role'] }}" when: - lab in rh_labs or lab == "byol" + - not (enable_bond | default(false)) + - hostvars[item]['mac_address'] is defined - hostvars[item]['mac_address'] | lower in host_macs loop: "{{ inventory_nodes }}" + +- name: Set the hostname and role via bond mac addresses (bonded) + set_fact: + hostname: "{{ item }}" + host_role: "{{ hostvars[item]['role'] }}" + when: + - lab in rh_labs or lab == "byol" + - enable_bond | default(false) + - hostvars[item]['bond0_macs'] is defined + - (hostvars[item]['bond0_macs'].split(',')[0] | lower in host_macs) or (hostvars[item]['bond0_macs'].split(',')[1] | lower in host_macs) + loop: "{{ inventory_nodes }}" + - name: Set the hostname and role via bmc address set_fact: hostname: "{{ item }}"