From 5fd69e4ad7c52ad6e406d4b864aa90a0757a390a Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 25 Dec 2025 21:41:16 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor=20WOL?= =?UTF-8?q?=20parsing=20to=20use=20regex=5Ffindall=20and=20extract=20the?= =?UTF-8?q?=20first=20match?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This refactoring improves the robustness of WOL (Wake-on-LAN) packet parsing by using `regex_findall` to ensure that only the first matching MAC address is extracted, enhancing reliability in various network environments. --- tasks/main.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index da60dbd..5112e8f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -44,7 +44,7 @@ msg: > {{ wol_check.results | map(attribute='stdout_lines') | list }} -- name: Parse WOL support and state (robust) +- name: Parse WOL support and state (exception-safe) ansible.builtin.set_fact: wol_info: >- {{ @@ -54,13 +54,15 @@ 'supports_magic': ( item.stdout - | regex_search('Supports Wake-on:\\s*([a-z]+)', '\\1') + | regex_findall('Supports Wake-on:\\s*([a-z]+)') + | first | default('') ).find('g') != -1, 'current_state': ( item.stdout - | regex_search('Wake-on:\\s*([a-z]+)', '\\1') + | regex_findall('Wake-on:\\s*([a-z]+)') + | first | default('unknown') ) }