Skip to content

Commit 9e67ab0

Browse files
Merge pull request #680 from mcornea/autoconfigure_interface_vars
PERFSCALE-4093: Auto configure network interfaces vars
2 parents e425108 + 28e66e4 commit 9e67ab0

File tree

6 files changed

+83
-3
lines changed

6 files changed

+83
-3
lines changed

ansible/roles/create-inventory/tasks/main.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,25 @@
5252
validate_certs: false
5353
register: bastion_foreman_data
5454

55+
- name: Determine machine type for automatic interface configuration
56+
set_fact:
57+
machine_type: "{{ (ocpinventory.json.nodes[0].pm_addr.split('.')[0]).split('-')[-1] }}"
58+
5559
- name: Public VLAN autoconfiguration
5660
when: public_vlan
5761
block:
5862
- name: Public VLAN - Set controlplane_network_interface_idx to -1 for the last interface
5963
set_fact:
6064
controlplane_network_interface_idx: "-1"
6165

66+
- name: Public VLAN - Update bastion_controlplane_interface to use last interface
67+
set_fact:
68+
bastion_controlplane_interface: "{{ hw_nic_name[lab][machine_type][-1] }}"
69+
when:
70+
- bastion_controlplane_interface is not defined
71+
- lab in hw_nic_name
72+
- machine_type in hw_nic_name[lab]
73+
6274
- name: Public VLAN - Get assignment from quads
6375
uri:
6476
url: "https://{{ labs[lab]['quads'] }}/api/v3/assignments/active/{{ lab_cloud }}"
@@ -79,6 +91,31 @@
7991
cluster_name: "vlan{{ quads_assignment.json.vlan.vlan_id }}"
8092
when: cluster_name == "mno"
8193

94+
- name: Auto-configure bastion lab interface (only when not explicitly set)
95+
set_fact:
96+
bastion_lab_interface: "{{ hw_nic_name[lab][machine_type][0] }}"
97+
when:
98+
- bastion_lab_interface is not defined
99+
- lab in hw_nic_name
100+
- machine_type in hw_nic_name[lab]
101+
102+
- name: Auto-configure bastion controlplane interface (only when not explicitly set)
103+
set_fact:
104+
bastion_controlplane_interface: "{{ hw_nic_name[lab][machine_type][controlplane_network_interface_idx|int+1] }}"
105+
when:
106+
- bastion_controlplane_interface is not defined
107+
- lab in hw_nic_name
108+
- machine_type in hw_nic_name[lab]
109+
- not public_vlan
110+
111+
- name: Auto-configure controlplane lab interface (only when not explicitly set)
112+
set_fact:
113+
controlplane_lab_interface: "{{ hw_nic_name[lab][machine_type][0] }}"
114+
when:
115+
- controlplane_lab_interface is not defined
116+
- lab in hw_nic_name
117+
- machine_type in hw_nic_name[lab]
118+
82119
- name: Multi node cluster type tasks
83120
when: cluster_type == "mno"
84121
block:
@@ -294,6 +331,32 @@
294331
loop_control:
295332
index_var: idx
296333

334+
- name: Validate network interface variables are properly configured
335+
block:
336+
- name: Validate bastion_lab_interface is defined
337+
assert:
338+
that:
339+
- bastion_lab_interface is defined
340+
- bastion_lab_interface != ""
341+
fail_msg: "bastion_lab_interface is not properly configured. Check your all.yml configuration or verify lab/machine_type support in lab.yml"
342+
success_msg: "bastion_lab_interface is configured: {{ bastion_lab_interface }}"
343+
344+
- name: Validate bastion_controlplane_interface is defined
345+
assert:
346+
that:
347+
- bastion_controlplane_interface is defined
348+
- bastion_controlplane_interface != ""
349+
fail_msg: "bastion_controlplane_interface is not properly configured. Check your all.yml configuration or verify lab/machine_type support in lab.yml"
350+
success_msg: "bastion_controlplane_interface is configured: {{ bastion_controlplane_interface }}"
351+
352+
- name: Validate controlplane_lab_interface is defined
353+
assert:
354+
that:
355+
- controlplane_lab_interface is defined
356+
- controlplane_lab_interface != ""
357+
fail_msg: "controlplane_lab_interface is not properly configured. Check your all.yml configuration or verify lab/machine_type support in lab.yml"
358+
success_msg: "controlplane_lab_interface is configured: {{ controlplane_lab_interface }}"
359+
297360
- name: Place inventory file named {{ lab_cloud }}.local into inventory directory
298361
template:
299362
src: "inventory-{{ cluster_type }}.j2"

ansible/roles/create-inventory/templates/inventory-mno.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ base_dns_name={{ labs[lab]['base_dns_name'] }}
99
{% else %}
1010
base_dns_name={{ base_dns_name }}
1111
{% endif %}
12+
# Network interface configuration
13+
bastion_lab_interface={{ bastion_lab_interface }}
14+
bastion_controlplane_interface={{ bastion_controlplane_interface }}
15+
controlplane_lab_interface={{ controlplane_lab_interface }}
1216

1317
[bastion]
1418
{{ bastion_machine }} ansible_ssh_user=root bmc_address=mgmt-{{ bastion_machine }} lab_ip={{ bastion_foreman_data.json.ip }}

ansible/roles/create-inventory/templates/inventory-sno.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ base_dns_name={{ labs[lab]['base_dns_name'] }}
1414
{% else %}
1515
base_dns_name={{ base_dns_name }}
1616
{% endif %}
17+
# Network interface configuration
18+
bastion_lab_interface={{ bastion_lab_interface }}
19+
bastion_controlplane_interface={{ bastion_controlplane_interface }}
20+
controlplane_lab_interface={{ controlplane_lab_interface }}
1721

1822
[bastion]
1923
{{ bastion_machine }} ansible_ssh_user=root bmc_address=mgmt-{{ bastion_machine }} lab_ip={{ bastion_foreman_data.json.ip }}

ansible/roles/create-inventory/templates/inventory-vmno.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ base_dns_name={{ labs[lab]['base_dns_name'] }}
99
{% else %}
1010
base_dns_name={{ base_dns_name }}
1111
{% endif %}
12+
# Network interface configuration
13+
bastion_lab_interface={{ bastion_lab_interface }}
14+
bastion_controlplane_interface={{ bastion_controlplane_interface }}
15+
controlplane_lab_interface={{ controlplane_lab_interface }}
1216

1317
[bastion]
1418
{{ bastion_machine }} ansible_ssh_user=root bmc_address=mgmt-{{ bastion_machine }} lab_ip={{ bastion_foreman_data.json.ip }}

ansible/vars/all.sample.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ bastion_cluster_config_dir: /root/{{ cluster_type }}
5454

5555
smcipmitool_url:
5656

57-
bastion_lab_interface: eno1np0
58-
bastion_controlplane_interface: ens1f0
57+
# Network interfaces - these will be auto-configured based on lab and machine type
58+
# if not explicitly set. To override auto-configuration, uncomment and set values:
59+
# bastion_lab_interface: eno1np0
60+
# bastion_controlplane_interface: ens1f0
5961

6062
# Sets up Gogs a self-hosted git service on the bastion
6163
setup_bastion_gogs: false
@@ -70,7 +72,9 @@ use_bastion_registry: false
7072
# OCP node vars
7173
################################################################################
7274
# Network configuration for all mno/sno cluster nodes
73-
controlplane_lab_interface: eno1np0
75+
# This will be auto-configured based on lab and machine type if not explicitly set
76+
# To override auto-configuration, uncomment and set value:
77+
# controlplane_lab_interface: eno1np0
7478

7579
################################################################################
7680
# Extra vars

docs/tips-and-vars.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ _**Table of Contents**_
1717
## Network interface to vars table
1818

1919
Values here reflect the default (Network 1 which maps to `controlplane_network_interface_idx: 0`). See this [section](#using-other-network-interfaces) to generate the proper inventory for a different network.
20+
Note that if these variables are not explicitely set then Jetlag auto configures them.
2021

2122
**Scale Lab**
2223

0 commit comments

Comments
 (0)