refactor ♻️: Refactor task to detect physical NIC behind bridge

This refactoring involves restructuring the code to improve the detection mechanism for identifying the physical network interface card (NIC) that lies behind a bridge. The changes enhance the accuracy and efficiency of the task, making it more reliable in various network configurations.
This commit is contained in:
2025-12-21 18:58:06 +01:00
parent e531859ead
commit 8af1f7fd12

View File

@@ -15,16 +15,26 @@
wol_detected_interface: "{{ ansible_default_ipv4.interface }}"
when: wol_interface | default('') | length == 0
- name: Detect physical NIC enslaved to bridge
# - name: Detect physical NIC enslaved to bridge
# ansible.builtin.set_fact:
# wol_detected_phy: "{{ item }}"
# loop: "{{ ansible_interfaces }}"
# when:
# - wol_interface | default('') | length == 0
# - item != 'lo'
# - hostvars[inventory_hostname]['ansible_' + item] is defined
# - hostvars[inventory_hostname]['ansible_' + item].master is defined
# - hostvars[inventory_hostname]['ansible_' + item].master == wol_detected_bridge
- name: Detect physical NIC behind bridge
ansible.builtin.set_fact:
wol_detected_phy: "{{ item }}"
loop: "{{ ansible_interfaces }}"
wol_detected_phy: "{{ ansible_facts[wol_detected_bridge].interfaces[0] }}"
when:
- wol_interface | default('') | length == 0
- item != 'lo'
- hostvars[inventory_hostname]['ansible_' + item] is defined
- hostvars[inventory_hostname]['ansible_' + item].master is defined
- hostvars[inventory_hostname]['ansible_' + item].master == wol_detected_bridge
- ansible_facts[wol_detected_bridge] is defined
- ansible_facts[wol_detected_bridge].interfaces is defined
- ansible_facts[wol_detected_bridge].interfaces | length > 0
- name: Debug WoL interface selection
ansible.builtin.debug: