Skip to content

Commit 9a68859

Browse files
authored
Reduce looping in the hostname/role identification for RH lab MNO deployments (#586)
* Reduce looping in the hostname/role identification for RH lab MNO deployments * Force to lower case for CPT
1 parent bbaa05f commit 9a68859

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ansible/roles/wait-hosts-discovered/tasks/set_hostname_role.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
host_bmc: "{{ (discovered_host.inventory | from_json).bmc_address }}"
77
when: lab in cloud_labs
88

9-
- name: Set the host ID
9+
- name: Set the host id and list of mac addresses
1010
set_fact:
11-
host_interfaces: "{{ (discovered_host.inventory | from_json).interfaces }}"
1211
host_id: "{{ discovered_host.id }}"
12+
host_macs: "{{ (discovered_host.inventory | from_json) | json_query('interfaces[].mac_address') | lower }}"
1313

1414
- name: Set the hostname and role via mac address
1515
set_fact:
16-
hostname: "{{ item.0 }}"
17-
host_role: "{{ hostvars[item.0]['role'] }}"
16+
hostname: "{{ item }}"
17+
host_role: "{{ hostvars[item]['role'] }}"
1818
when:
1919
- lab in rh_labs
20-
- hostvars[item.0]['lab_mac'] == item.1.mac_address
21-
loop: "{{ inventory_nodes | product(host_interfaces) | list }}"
20+
- hostvars[item]['mac_address'] | lower in host_macs
21+
loop: "{{ inventory_nodes }}"
2222
loop_control:
23-
label: "{{ hostvars[item.0]['bmc_address'] }}"
23+
label: "{{ hostvars[item]['bmc_address'] }}"
2424

2525
- name: Set the hostname and role via bmc address
2626
set_fact:

0 commit comments

Comments
 (0)