refactor ♻️: Refactor WOL parsing logic
All checks were successful
ansible-lint / Ansible Lint (push) Successful in 9s

Updated WOL parsing to use `select` and `join` for guaranteed matches, improving reliability.
This commit is contained in:
2025-12-25 21:45:03 +01:00
parent 5fd69e4ad7
commit 670021fcc8

View File

@@ -44,7 +44,7 @@
msg: >
{{ wol_check.results | map(attribute='stdout_lines') | list }}
- name: Parse WOL support and state (exception-safe)
- name: Parse WOL support and state (guaranteed match)
ansible.builtin.set_fact:
wol_info: >-
{{
@@ -53,15 +53,15 @@
item.item: {
'supports_magic':
(
item.stdout
| regex_findall('Supports Wake-on:\\s*([a-z]+)')
| first
| default('')
item.stdout_lines
| select('search', 'Supports Wake-on:')
| join('')
).find('g') != -1,
'current_state':
(
item.stdout
| regex_findall('Wake-on:\\s*([a-z]+)')
item.stdout_lines
| select('search', '^\\s*Wake-on:')
| map('regex_replace', '.*Wake-on:\\s*', '')
| first
| default('unknown')
)