Thanks again Vladimir. json_query was the answer again. Need to read up on that some more to understand the syntax. These examples are extremely helpful.
Again thank you for taking the time On Fri, Nov 20, 2020 at 1:36 AM Vladimir Botka <[email protected]> wrote: > 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/CAANJ-QR7V3KpGe2qzFagYu8HS6xY%3Dy-fLjP62KiAKqHyDMc_Zg%40mail.gmail.com.
