From 263d061cb1b83e6e0a3fac65a40b9bd61ae55655 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 26 Dec 2025 06:30:58 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor=20WOL?= =?UTF-8?q?=20capability=20validation=20to=20use=20ethtool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This refactoring updates the method for validating Wake-On-LAN (WOL) capabilities by utilizing the ethtool utility instead of a previous approach. This change improves accuracy and efficiency in determining WOL support for network interfaces. --- tasks/main.yml | 66 +++++--------------------------------------------- 1 file changed, 6 insertions(+), 60 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 234f5cb..3492b75 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -31,71 +31,17 @@ msg: > {{ en_interfaces }} -- name: Validate WOL capability using ethtool for detected interfaces - ansible.builtin.command: "ethtool {{ item }}" - register: wol_check +- name: Check WoL status with ethtool + shell: "ethtool {{ item }} | grep 'Wake-on'" + register: wol_status changed_when: false failed_when: false loop: "{{ en_interfaces }}" when: en_interfaces | length > 0 -- name: Display ethtool output for detected interfaces - ansible.builtin.debug: - msg: > - {{ wol_check.results | map(attribute='stdout_lines') | list }} - -# - name: Parse WOL support and state (guaranteed match) -# ansible.builtin.set_fact: -# wol_info: >- -# {{ -# wol_info | default({}) | -# combine({ -# item.item: { -# 'supports_magic': -# ( -# item.stdout_lines -# | select('search', 'Supports Wake-on:') -# | join('') -# ).find('g') != -1, -# 'current_state': -# ( -# item.stdout_lines -# | map('trim') -# | select('match', '^Wake-on:') -# | map('regex_replace', 'Wake-on:\\s*', '') -# | first -# | default('unknown') -# ) -# } -# }) -# }} -# loop: "{{ wol_check.results }}" - -- name: Parse WOL support and state (final) - ansible.builtin.set_fact: - wol_info: >- - {{ - wol_info | default({}) | - combine({ - item.item: { - 'supports_magic': - ( - item.stdout - | regex_findall('Supports Wake-on:\\s*([a-z]+)') - | first - | default('') - ).find('g') != -1, - 'current_state': - ( - item.stdout - | regex_findall('\\n\\s*Wake-on:\\s*([a-z]+)') - | first - | default('unknown') - ) - } - }) - }} - loop: "{{ wol_check.results }}" +- name: Display WoL status + debug: + msg: "{{ wol_status.stdout }}" - name: Display WOL status summary ansible.builtin.debug: