refactor ♻️: Refactor task to detect physical NIC enslaved to bridge and add debug facts

This refactoring improves the task by detecting which physical network interface card (NIC) is enslaved to a bridge and adds debug facts for better visibility during execution.
This commit is contained in:
2025-12-21 19:47:24 +01:00
parent 8af1f7fd12
commit 7f86cae2ed

View File

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