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:
@@ -15,25 +15,30 @@
|
||||
wol_detected_interface: "{{ ansible_default_ipv4.interface }}"
|
||||
when: wol_interface | default('') | length == 0
|
||||
|
||||
# - 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: Debug facts
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "{{ hostvars[inventory_hostname] }}"
|
||||
|
||||
- name: Detect physical NIC behind bridge
|
||||
- name: Detect physical NIC enslaved to bridge
|
||||
ansible.builtin.set_fact:
|
||||
wol_detected_phy: "{{ ansible_facts[wol_detected_bridge].interfaces[0] }}"
|
||||
wol_detected_phy: "{{ item }}"
|
||||
loop: "{{ ansible_interfaces }}"
|
||||
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
|
||||
- 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: "{{ 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
|
||||
|
||||
Reference in New Issue
Block a user