From aea02a8e39d9b7bb1c5f91e7d1d769db736811d9 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 26 Dec 2025 09:24:04 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor=20Wak?= =?UTF-8?q?e-on-LAN=20config=20to=20use=20dynamic=20mode=20selection,=20re?= =?UTF-8?q?move=20unused=20bridge=20mapping.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This refactoring updates the Wake-on-LAN configuration to dynamically select modes based on system capabilities and removes unnecessary logic related to bridge mappings. --- tasks/main.yml | 93 ++------------------------------------------------ 1 file changed, 3 insertions(+), 90 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index d19c18b..cd82888 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -57,102 +57,15 @@ when: en_interfaces | length > 0 - name: Enable Wake-on-LAN (magic packet) when supported - ansible.builtin.command: "ethtool -s {{ item.0 }} wol g" + ansible.builtin.command: "ethtool -s {{ item.0 }} wol {{ wol_mode }}" loop: "{{ en_interfaces | zip(wol_enabled.results, wol_supported.results) | list }}" loop_control: label: "{{ item.0 }}" when: - - "'g' not in item.1.stdout" - - "'g' in item.2.stdout" + - "{{ wol_mode }} not in item.1.stdout" + - "{{ wol_mode }} in item.2.stdout" -# # ============================================================ -# # Map bridges to physical NICs using Ansible facts -# # ============================================================ -# - name: Get bridge link information -# ansible.builtin.command: "bridge link show" -# register: bridge_links -# changed_when: false -# check_mode: false - -# - name: Initialize detected interfaces dictionary -# ansible.builtin.set_fact: -# wol_detected_interfaces: {} - -# - name: Detect physical NIC for each bridge -# ansible.builtin.set_fact: -# wol_detected_interfaces: >- -# {{ -# wol_detected_interfaces | combine({ -# item: ( -# bridge_links.stdout_lines -# | select('search', 'master ' ~ item) -# | map('regex_replace', '^\\d+: ([a-z0-9@.]+):.*$', '\\1') -# | reject('search', '^(veth|tap|fw)') -# | reject('search', '^\\d+:') -# | select('in', wol_supported_interfaces) -# | first | default('') -# ) -# }) -# }} -# loop: "{{ wol_bridges_list }}" -# loop_control: -# label: "{{ item }}" - -# - name: Check for bond0 backing -# when: bond_info.rc == 0 -# block: -# - name: Detect if any bridge is backed by bond0 -# ansible.builtin.set_fact: -# wol_has_bond0: "{{ wol_detected_interfaces.values() | select('search', 'bond0') | length > 0 }}" - -# - name: Extract bond0 slaves if present -# ansible.builtin.set_fact: -# wol_bond0_slaves: >- -# {{ -# (bond_info.stdout | regex_findall('Slave Interface: ([a-zA-Z0-9]+)')) | list -# }} -# when: wol_has_bond0 | default(false) - -# # ============================================================ -# # Validate configuration and resolve to physical NICs -# # ============================================================ -# - name: Fail if any bridge backing NIC could not be detected -# ansible.builtin.fail: -# msg: > -# Unable to detect physical NIC backing bridge(s): {{ unresolved_bridges | join(', ') }}. -# Please verify bridges exist and are backed by WOL-capable interfaces. -# Available WOL-capable interfaces: {{ wol_supported_interfaces | join(', ') }} -# vars: -# unresolved_bridges: "{{ wol_detected_interfaces | dict2items | selectattr('value', 'equalto', '') | map(attribute='key') | list }}" -# when: unresolved_bridges | length > 0 - -# - name: Build final WOL interfaces list (deduped physical NICs) -# ansible.builtin.set_fact: -# wol_final_interfaces: "{{ wol_detected_interfaces.values() | unique | list }}" - -# # ============================================================ -# # Check current WOL status to ensure idempotency -# # ============================================================ -# - name: Get current WOL status -# ansible.builtin.command: "ethtool {{ item }}" -# register: wol_current_status -# changed_when: false -# failed_when: false -# loop: "{{ wol_final_interfaces }}" -# loop_control: -# label: "{{ item }}" - -# - name: Build list of NICs needing WOL enabled -# ansible.builtin.set_fact: -# wol_needs_enable: >- -# {{ -# wol_current_status.results -# | selectattr('stdout', 'search', 'Wake-on: [^g]') -# | map(attribute='item') -# | list -# }} - # # ============================================================ # # Enable WOL immediately (only if needed) # # ============================================================