From c35ff62880eea823394266a982735a1fc2a2fedb Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 26 Dec 2025 08:04:06 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor=20tas?= =?UTF-8?q?k=20to=20extract=20Supports=20Wake-on=20per=20interface=20using?= =?UTF-8?q?=20set=5Ffact=20and=20loop.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This refactoring extracts the logic for handling Wake-on settings per network interface into a reusable task. It uses `set_fact` and loops to simplify the configuration process and improve readability. --- tasks/main.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 1d29189..4e7641a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -56,10 +56,22 @@ ansible.builtin.debug: var: wol_status +- name: Extract Supports Wake-on per interface + ansible.builtin.set_fact: + supports_wake_on: >- + {{ + supports_wake_on | default({}) | + combine({ + item.item: + (item.stdout | regex_search('Supports Wake-on:\\s*(\\S+)', '\\1')) + }) + }} + loop: "{{ wol_status.results }}" + when: item.stdout is defined -- name: Extract Supports Wake-on value - set_fact: - supports_wake_on: "{{ wol_status.results | regex_search('(?m)^\\s*Supports Wake-on:\\s*(\\S+)', '\\1') }}" +# - name: Extract Supports Wake-on value +# set_fact: +# supports_wake_on: "{{ wol_status.results | regex_search('(?m)^\\s*Supports Wake-on:\\s*(\\S+)', '\\1') }}" - name: Show Supports Wake-on value debug: