From 3f61c1c48a7e996baf6f642d6ef57336e466fbd9 Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 23 Dec 2025 21:24:47 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Extract=20and?= =?UTF-8?q?=20select=20physical=20NIC=20candidates=20for=20wol=5Fbridge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored the task to improve code organization and clarity by extracting the process of selecting physical NIC candidates for the wol_bridge feature. This change enhances maintainability and readability. --- tasks/main.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 4155ebe..ec427c0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,24 +14,25 @@ changed_when: false failed_when: false -- name: Show bridge_links +- name: Show bridge_links.stdout_lines ansible.builtin.debug: - msg: "{{ bridge_links }}" - + msg: "{{ bridge_links.stdout_lines }}" - name: "Detect physical NIC backing {{ wol_bridge }}" ansible.builtin.set_fact: - wol_detected_phy: >- + wol_detected_phy_candidates: >- {{ bridge_links.stdout_lines | select('search', 'master ' ~ wol_bridge) - | select('match', '^\\d+: [a-zA-Z0-9]+:') - | reject('search', ' veth') - | reject('search', ' tap') - | map('regex_replace', '^\\d+: ([^:]+):.*', '\\1') - | first + | map('regex_replace', '^\\d+: ([^:@]+).*', '\\1') + | reject('search', '^(veth|tap|fw)') + | list }} +- name: Select first physical NIC candidate + ansible.builtin.set_fact: + wol_detected_phy: "{{ wol_detected_phy_candidates[0] | default('') }}" + - name: Fail if vmbr0 backing NIC could not be detected ansible.builtin.fail: msg: >