refactor ♻️: Refactor WOL parsing to use regex_findall and extract the first match
All checks were successful
ansible-lint / Ansible Lint (push) Successful in 9s

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.
This commit is contained in:
2025-12-25 21:41:16 +01:00
parent f6d35d0abb
commit 5fd69e4ad7

View File

@@ -44,7 +44,7 @@
msg: > msg: >
{{ wol_check.results | map(attribute='stdout_lines') | list }} {{ 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: ansible.builtin.set_fact:
wol_info: >- wol_info: >-
{{ {{
@@ -54,13 +54,15 @@
'supports_magic': 'supports_magic':
( (
item.stdout item.stdout
| regex_search('Supports Wake-on:\\s*([a-z]+)', '\\1') | regex_findall('Supports Wake-on:\\s*([a-z]+)')
| first
| default('') | default('')
).find('g') != -1, ).find('g') != -1,
'current_state': 'current_state':
( (
item.stdout item.stdout
| regex_search('Wake-on:\\s*([a-z]+)', '\\1') | regex_findall('Wake-on:\\s*([a-z]+)')
| first
| default('unknown') | default('unknown')
) )
} }