refactor ♻️: Refactor WOL capability validation to use ethtool
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s
This refactoring updates the method for validating Wake-On-LAN (WOL) capabilities by utilizing the ethtool utility instead of a previous approach. This change improves accuracy and efficiency in determining WOL support for network interfaces.
This commit is contained in:
@@ -31,71 +31,17 @@
|
||||
msg: >
|
||||
{{ en_interfaces }}
|
||||
|
||||
- name: Validate WOL capability using ethtool for detected interfaces
|
||||
ansible.builtin.command: "ethtool {{ item }}"
|
||||
register: wol_check
|
||||
- name: Check WoL status with ethtool
|
||||
shell: "ethtool {{ item }} | grep 'Wake-on'"
|
||||
register: wol_status
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
loop: "{{ en_interfaces }}"
|
||||
when: en_interfaces | length > 0
|
||||
|
||||
- name: Display ethtool output for detected interfaces
|
||||
ansible.builtin.debug:
|
||||
msg: >
|
||||
{{ wol_check.results | map(attribute='stdout_lines') | list }}
|
||||
|
||||
# - 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:
|
||||
wol_info: >-
|
||||
{{
|
||||
wol_info | default({}) |
|
||||
combine({
|
||||
item.item: {
|
||||
'supports_magic':
|
||||
(
|
||||
item.stdout
|
||||
| regex_findall('Supports Wake-on:\\s*([a-z]+)')
|
||||
| first
|
||||
| default('')
|
||||
).find('g') != -1,
|
||||
'current_state':
|
||||
(
|
||||
item.stdout
|
||||
| regex_findall('\\n\\s*Wake-on:\\s*([a-z]+)')
|
||||
| first
|
||||
| default('unknown')
|
||||
)
|
||||
}
|
||||
})
|
||||
}}
|
||||
loop: "{{ wol_check.results }}"
|
||||
- name: Display WoL status
|
||||
debug:
|
||||
msg: "{{ wol_status.stdout }}"
|
||||
|
||||
- name: Display WOL status summary
|
||||
ansible.builtin.debug:
|
||||
|
||||
Reference in New Issue
Block a user