From a96493eeabc821b16ab076319bf8620a45729443 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 26 Dec 2025 09:17:42 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor=20Wak?= =?UTF-8?q?e-on-LAN=20task=20to=20use=20`zip`=20for=20parallel=20processin?= =?UTF-8?q?g=20of=20interfaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This refactoring improves the efficiency of the Wake-on-LAN task by utilizing the `zip` function to process multiple network interfaces in parallel. This change enhances performance and allows WOL functionality when supported on multiple interfaces. --- tasks/main.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index f81f7c8..5a16026 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -57,11 +57,20 @@ when: en_interfaces | length > 0 - name: Enable Wake-on-LAN (magic packet) when supported - ansible.builtin.command: "ethtool -s {{ item }} wol g" + ansible.builtin.command: "ethtool -s {{ item.interface }} wol g" + loop: "{{ en_interfaces | zip(wol_enabled.results, wol_supported.results) | list }}" + loop_control: + label: "{{ item.0 }}" + vars: + # item.0 = interface + # item.1 = wol_enabled result + # item.2 = wol_supported result + interface: "{{ item.0 }}" + wol_enabled_result: "{{ item.1 }}" + wol_supported_result: "{{ item.2 }}" when: - - "'g' not in wol_enabled.results[loop.index0].stdout" - - "'g' in wol_supported.results[loop.index0].stdout" - loop: "{{ en_interfaces }}" + - "'g' not in wol_enabled_result.stdout" + - "'g' in wol_supported_result.stdout" # # ============================================================