refactor ♻️: Refactor interface filtering to use dict2items
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s
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:
@@ -22,9 +22,21 @@
|
|||||||
msg: >
|
msg: >
|
||||||
{{ ansible_facts.interfaces }}
|
{{ 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"
|
- name: Get interfaces starting with "en" or "eth"
|
||||||
ansible.builtin.set_fact:
|
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
|
- name: Display selected interfaces
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
|
|||||||
Reference in New Issue
Block a user