refactor ♻️: Refactor interface filtering to use dict2items
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s

This refactoring improves the readability of the interface filtering logic by utilizing the `dict2items` function, making the code more maintainable and easier to understand.
This commit is contained in:
2025-12-26 06:42:46 +01:00
parent 263d061cb1
commit 756e39a498

View File

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