Hi matt, 

Thanks for your reply !

That's already a good example, But I need somehow also to retrieve the 
index which is the chain number.

Let's simplify and say we only have one type of deployment (routed or 
bridged):
chains_config:
    1:
        foo: bar
        configs:
            - type: bridged
              version: 0.2
    2:
        foo: baz
        configs:
            - type: routed
              version: 1.0

To briefly explain the context we have two type of network deployment 
(routed or bridged). Each of these network deployment have their own
set of network interfaces / VLANs. The VLAN used is guess from the chain 
number and type of deployment. And the type of deployment is specified in 
the chains_config dict.
On top of this network architecture a docker container is applied for 
network type / VLANs.

A dumb naive approach would be:

- name: Creating docker network for the chain
  include_role:
    name: docker_chain_network
  vars:
    docker_network:
      name: macvlan{{item.key}}0{{ '6' if item.value.type == 'routed' else 
'5' }}
      driver: macvlan
      driver_options:
        parent: "{{ 'eno52' if routed else 'eno51' }}".{{item.key}}0{{ '6' 
if item.value.type == routed else '5' }}"
  with: ? map/select ?

item.key ==> Would be each index of chains[] list (iteratively). 
item.value.type ==> Would be type of deployment based the index above; like 
in python: chains_config[item.key]['configs']['type']

docker_chain_network is just a role applying docker_network module with the 
vars passed to the role.

This is rather complex stuff. Thanks for taking your time and for your 
answers.

Best regards,

Lionel.


Le jeudi 27 septembre 2018 17:06:29 UTC+2, Matt Martz a écrit :
>
> What is your end goal?  How do you plan to use this data, assuming you 
> could loop the way you want?
>
> Something like the following:
>
> "{{ chains|map('extract', 
> chains_config)|map(attribute='configs')|flatten|map(attribute='type')|flatten 
> }}"
>
> Gives:
>
> ok: [localhost] => {
>     "msg": [
>         "routed",
>         "bridged",
>         "routed",
>         "bridged"
>     ]
> }
>
> On Thu, Sep 27, 2018 at 9:23 AM Lionel H <[email protected] 
> <javascript:>> wrote:
>
>> Hi all, 
>>
>> Hope I will find the information here :-)
>>
>> I need to loop over 2 lists, the first one is just a list of Integers, 
>> things get tricky here because the second list needs the input from the 
>> first list to loop over. In fact, the list is included in a dictionary 
>> where keys are integers.
>>
>> One example will be more self-explanatory:
>>
>> 1st list:
>> chains = [1, 2, 3, 4, 5]
>>
>> 2nd list:
>> chains_config:
>>     1:
>>         foo: bar
>>         configs:
>>             - type: routed
>>               version: 0.1
>>             - type: bridged
>>               version: 0.2
>>     2:
>>         foo: baz
>>         configs:
>>             - type: routed
>>               version: 1.0
>>             - type: bridged
>>               version: 1.1
>> ... and 3, 4, 5 you get the idea.
>>
>> So I need to loop over this configs key and the chains list is defined by 
>> the user input.
>>
>> In python I would do this way:
>>
>> for chain in chains:
>>      for config in chains_config[chain]['configs']:
>>          print(config.type).
>>
>> Now, and to convert this into ansible code?
>>
>> I hope that you get the point :-)
>>
>>
>> Best regards,
>>
>> Lionel.
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/5edde98f-64f5-447f-beae-22dc5d21a00b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/5edde98f-64f5-447f-beae-22dc5d21a00b%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f5aa1b13-bd87-421b-b1f1-a77a0d9593b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to