refactor ♻️: Extract and select physical NIC candidates for wol_bridge

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.
This commit is contained in:
2025-12-23 21:24:47 +01:00
parent 5f80e247ec
commit 3f61c1c48a

View File

@@ -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: >