From 672d0457febd48e7f0c254db290111cb7cdae9bc Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 24 Dec 2025 10:55:15 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor=20WOL?= =?UTF-8?q?=20status=20parsing=20and=20add=20Wake-on-LAN=20enabling=20logi?= =?UTF-8?q?c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit refactors the existing code for parsing Wake-on-LAN (WOL) status and introduces new functionality to enable WOL. The changes improve the clarity and efficiency of the WOL handling mechanism. --- tasks/main.yml | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index f7399c2..7d8bff2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -44,26 +44,48 @@ msg: > {{ wol_check.results | map(attribute='stdout_lines') | list }} -- name: Build WOL status per interface (safe) +- name: Parse WOL support and state ansible.builtin.set_fact: - wol_status: >- + wol_info: >- {{ - wol_status | default({}) | + wol_info | default({}) | combine({ - item.item: - ( - item.stdout - | regex_findall('Wake-on:\\s*(\\S+)') - | first - | default('Not supported') - ) + item.item: { + 'supports_magic': + ( + item.stdout_lines + | select('search', '^\\s*Supports Wake-on:') + | join(' ') + | regex_search('g') + ) is not none, + 'current_state': + ( + item.stdout_lines + | select('search', '^\\s*Wake-on:') + | map('regex_replace', '^\\s*Wake-on:\\s*', '') + | first + | default('unknown') + ) + } }) }} loop: "{{ wol_check.results }}" -- name: Display WOL support status +- name: Enable Wake-on-LAN (magic packet) when supported + ansible.builtin.command: "ethtool -s {{ item.key }} wol g" + when: + - item.value.supports_magic + - item.value.current_state != 'g' + loop: "{{ wol_info | dict2items }}" + +- name: Display WOL status summary ansible.builtin.debug: - var: wol_status + msg: > + Interface {{ item.key }}: + Supported={{ item.value.supports_magic }}, + Current={{ item.value.current_state }} + loop: "{{ wol_info | dict2items }}" + # # ============================================================ # # Map bridges to physical NICs using Ansible facts