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: >
|
msg: >
|
||||||
{{ en_interfaces }}
|
{{ en_interfaces }}
|
||||||
|
|
||||||
- name: Validate WOL capability using ethtool for detected interfaces
|
- name: Check WoL status with ethtool
|
||||||
ansible.builtin.command: "ethtool {{ item }}"
|
shell: "ethtool {{ item }} | grep 'Wake-on'"
|
||||||
register: wol_check
|
register: wol_status
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
loop: "{{ en_interfaces }}"
|
loop: "{{ en_interfaces }}"
|
||||||
when: en_interfaces | length > 0
|
when: en_interfaces | length > 0
|
||||||
|
|
||||||
- name: Display ethtool output for detected interfaces
|
- name: Display WoL status
|
||||||
ansible.builtin.debug:
|
debug:
|
||||||
msg: >
|
msg: "{{ wol_status.stdout }}"
|
||||||
{{ 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 summary
|
- name: Display WOL status summary
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
|
|||||||
Reference in New Issue
Block a user