refactor ♻️: Refactor WOL parsing task for better readability and efficiency
All checks were successful
ansible-lint / Ansible Lint (push) Successful in 8s
All checks were successful
ansible-lint / Ansible Lint (push) Successful in 8s
This refactoring improves the structure and performance of the Wake-On-LAN (WOL) packet parsing task, enhancing both its readability and execution speed.
This commit is contained in:
@@ -44,7 +44,34 @@
|
|||||||
msg: >
|
msg: >
|
||||||
{{ wol_check.results | map(attribute='stdout_lines') | list }}
|
{{ wol_check.results | map(attribute='stdout_lines') | list }}
|
||||||
|
|
||||||
- name: Parse WOL support and state (guaranteed match)
|
# - 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:
|
ansible.builtin.set_fact:
|
||||||
wol_info: >-
|
wol_info: >-
|
||||||
{{
|
{{
|
||||||
@@ -53,16 +80,15 @@
|
|||||||
item.item: {
|
item.item: {
|
||||||
'supports_magic':
|
'supports_magic':
|
||||||
(
|
(
|
||||||
item.stdout_lines
|
item.stdout
|
||||||
| select('search', 'Supports Wake-on:')
|
| regex_findall('Supports Wake-on:\\s*([a-z]+)')
|
||||||
| join('')
|
| first
|
||||||
|
| default('')
|
||||||
).find('g') != -1,
|
).find('g') != -1,
|
||||||
'current_state':
|
'current_state':
|
||||||
(
|
(
|
||||||
item.stdout_lines
|
item.stdout
|
||||||
| map('trim')
|
| regex_findall('\\n\\s*Wake-on:\\s*([a-z]+)')
|
||||||
| select('match', '^Wake-on:')
|
|
||||||
| map('regex_replace', 'Wake-on:\\s*', '')
|
|
||||||
| first
|
| first
|
||||||
| default('unknown')
|
| default('unknown')
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user