On Thu, 19 Nov 2020 14:20:30 -0800 (PST) "[email protected]" <[email protected]> wrote:
> - name: Create a list of interfaces that are PortChannel Memebers
> set_fact:
> exclude_ints: "{{ item.value.port_channel.port_channel_member_intfs
> }}"
> loop: "{{ ansible_facts.po_ch.interfaces|dict2items }}"
> tags: debug
Either concatenate the lists in the loop
- set_fact:
exclude_ints: "{{ exclude_ints|default([]) +
[item.value.port_channel.port_channel_member_intfs]
}}"
loop: "{{ po_ch.interfaces|dict2items }}"
or use json_query
- set_fact:
exclude_ints: "{{ po_ch.interfaces|json_query(query) }}"
vars:
query: '*.port_channel.port_channel_member_intfs'
In both cases the result will be a list of lists
exclude_ints:
- - GigabitEthernet1/0/37
- GigabitEthernet1/0/38
- - GigabitEthernet1/1/2
- GigabitEthernet1/1/4
In both cases it's possible to flatten the list if needed. For example
- set_fact:
exclude_ints: "{{ po_ch.interfaces|json_query(query)|
flatten }}"
vars:
query: '*.port_channel.port_channel_member_intfs'
gives
exclude_ints:
- GigabitEthernet1/0/37
- GigabitEthernet1/0/38
- GigabitEthernet1/1/2
- GigabitEthernet1/1/4
--
Vladimir Botka
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/20201120083606.1fe0b911%40gmail.com.
pgph9G0VfbZxY.pgp
Description: OpenPGP digital signature
