OK, I got it, but I'm sure there is a more elegant and simpler way to 
achieve the same result:
        - name: Removing a <nic_id> from the dictionary matching the 
<net_id>
          vars:
                vpc:
                        provider:
                                - net_type: 'db'
                                  net_ipv4_subnet: '10.0.0.0/16'
                                  net_ipv6_subnet: 'FD00::/64'
                                  net_id: '0'
                                  nic_ids:
                                        - 1111111111
                                        - 2222222222
                                - net_type: 'dns'
                                  net_ipv4_subnet: '10.1.0.0/16'
                                  net_ipv6_subnet: 'FD01::/64'
                                  net_id: '1'
                                  nic_ids:
                                        - 3333333333
                                        - 4444444444
                                - net_type: 'ns'
                                  net_ipv4_subnet: '10.2.0.0/16'
                                  net_ipv6_subnet: 'FD02::/64'
                                  net_id: '2'
                                  nic_ids:
                                        - 5555555555
                                        - 6666666666
                nic_ids_:
                        - 4444444444
                new_nic_ids: "{{ vpc.provider | selectattr('net_id', 'eq', 
'1') | map(attribute= 'nic_ids') | first | difference(nic_ids_) }}"
                seed_vpc:
                        provider:
                                - net_id: '1'
                                  nic_ids: "{{ new_nic_ids }}"
                new_vpc:
                        provider:
                                "{{ [vpc.provider, seed_vpc.provider] | 
community.general.lists_mergeby('net_id', recursive=True, 
list_merge='replace') }}"
          debug:
                msg: "{{ new_vpc }}"

On Friday, August 25, 2023 at 4:22:09 PM UTC+2 jean-christophe manciot 
wrote:

> Here is how to get the new list:
>         - name: Removing a <nic_id> from the list inside the dictionary 
> matching the <net_id>
>           vars:
>
>                 vpc:
>                         provider:
>                                 - net_type: 'db'
>                                   net_ipv4_subnet: '10.0.0.0/16'
>                                   net_ipv6_subnet: 'FD00::/64'
>                                   net_id: '0'
>                                   nic_ids:
>                                         - 1111111111
>                                         - 2222222222
>                                 - net_type: 'dns'
>                                   net_ipv4_subnet: '10.1.0.0/16'
>                                   net_ipv6_subnet: 'FD01::/64'
>                                   net_id: '1'
>                                   nic_ids:
>                                         - 3333333333
>                                         - 4444444444
>                                 - net_type: 'ns'
>                                   net_ipv4_subnet: '10.2.0.0/16'
>                                   net_ipv6_subnet: 'FD02::/64'
>                                   net_id: '2'
>                                   nic_ids:
>                                         - 5555555555
>                                         - 6666666666
>                 nic_ids_:
>                         - 4444444444
>                 new_nic_ids: "{{ vpc.provider | selectattr('net_id', 'eq', 
> '1') | map(attribute= 'nic_ids') | first | difference(nic_ids_) }}"
>           debug: 
>                 msg: "{{ new_nic_ids }}"
>
> But I don't know how to get the updated <vpc>.
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3b585de9-dcaa-467d-bd2c-9708cbaa496cn%40googlegroups.com.

Reply via email to