From 756e39a498c7a061333e87c97dbc18c4a6cbb808 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 26 Dec 2025 06:42:46 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor=20int?= =?UTF-8?q?erface=20filtering=20to=20use=20dict2items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This refactoring improves the readability of the interface filtering logic by utilizing the `dict2items` function, making the code more maintainable and easier to understand. --- tasks/main.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 3492b75..afc596d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -22,9 +22,21 @@ msg: > {{ ansible_facts.interfaces }} +# - name: Get interfaces starting with "en" or "eth" +# ansible.builtin.set_fact: +# en_interfaces: "{{ ansible_facts.interfaces | select('match', '^eth|^ens|^enp') | unique | list }}" + - name: Get interfaces starting with "en" or "eth" ansible.builtin.set_fact: - en_interfaces: "{{ ansible_facts.interfaces | select('match', '^eth|^ens|^enp') | unique | list }}" + en_interfaces: > + {{ + ansible_facts.interfaces | + dict2items | + map('attribute=item.key') | + select('match', '^eth|^ens|^enp') | + unique | + list + }} - name: Display selected interfaces ansible.builtin.debug: