diff --git a/tasks/main.yml b/tasks/main.yml index f7399c2..7d8bff2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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