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
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:
@@ -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')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user