refactor ♻️: Refactor WOL status parsing and add Wake-on-LAN enabling logic
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s
This commit refactors the existing code for parsing Wake-on-LAN (WOL) status and introduces new functionality to enable WOL. The changes improve the clarity and efficiency of the WOL handling mechanism.
This commit is contained in:
@@ -44,26 +44,48 @@
|
||||
msg: >
|
||||
{{ wol_check.results | map(attribute='stdout_lines') | list }}
|
||||
|
||||
- name: Build WOL status per interface (safe)
|
||||
- name: Parse WOL support and state
|
||||
ansible.builtin.set_fact:
|
||||
wol_status: >-
|
||||
wol_info: >-
|
||||
{{
|
||||
wol_status | default({}) |
|
||||
wol_info | default({}) |
|
||||
combine({
|
||||
item.item:
|
||||
(
|
||||
item.stdout
|
||||
| regex_findall('Wake-on:\\s*(\\S+)')
|
||||
| first
|
||||
| default('Not supported')
|
||||
)
|
||||
item.item: {
|
||||
'supports_magic':
|
||||
(
|
||||
item.stdout_lines
|
||||
| select('search', '^\\s*Supports Wake-on:')
|
||||
| join(' ')
|
||||
| regex_search('g')
|
||||
) is not none,
|
||||
'current_state':
|
||||
(
|
||||
item.stdout_lines
|
||||
| select('search', '^\\s*Wake-on:')
|
||||
| map('regex_replace', '^\\s*Wake-on:\\s*', '')
|
||||
| first
|
||||
| default('unknown')
|
||||
)
|
||||
}
|
||||
})
|
||||
}}
|
||||
loop: "{{ wol_check.results }}"
|
||||
|
||||
- name: Display WOL support status
|
||||
- name: Enable Wake-on-LAN (magic packet) when supported
|
||||
ansible.builtin.command: "ethtool -s {{ item.key }} wol g"
|
||||
when:
|
||||
- item.value.supports_magic
|
||||
- item.value.current_state != 'g'
|
||||
loop: "{{ wol_info | dict2items }}"
|
||||
|
||||
- name: Display WOL status summary
|
||||
ansible.builtin.debug:
|
||||
var: wol_status
|
||||
msg: >
|
||||
Interface {{ item.key }}:
|
||||
Supported={{ item.value.supports_magic }},
|
||||
Current={{ item.value.current_state }}
|
||||
loop: "{{ wol_info | dict2items }}"
|
||||
|
||||
|
||||
# # ============================================================
|
||||
# # Map bridges to physical NICs using Ansible facts
|
||||
|
||||
Reference in New Issue
Block a user