refactor ♻️: Refactor Wake-on-LAN config to use dynamic mode selection, remove unused bridge mapping.
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s

This refactoring updates the Wake-on-LAN configuration to dynamically select modes based on system capabilities and removes unnecessary logic related to bridge mappings.
This commit is contained in:
2025-12-26 09:24:04 +01:00
parent 6a5c9f5967
commit aea02a8e39

View File

@@ -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)
# # ============================================================