Hi Felix,
Oh waw! Definitely what I was looking for. Shame that we have to resort to
custom plugins to achieve such a common things..
In my findings I was hoping maybe to find some sort of lookup plugins to
filter a dict based on a provided list of keys like:
{{ mydict | filter_by_keys([1, 2]) }} to only select those keys from the
dictionary but it seems not yet implemented! Maybe a good entrypoint for me
to start
digging into ansible plugin creation :-)
Anyway, this is working now.
Huge thanks ;-)
Lionel.
Le vendredi 28 septembre 2018 22:31:36 UTC+2, Felix Fontein a écrit :
>
> Hi Lionel,
>
> I've written a lookup plugin
> (https://github.com/felixfontein/ansible-dependentloop/) which you
> could use for this:
>
> - debug:
> msg: "index={{ item.0 }} foo={{ chains_config[item.0].foo }}
> type={{ index.1.type }} version={{ index.1.version }}"
> with_dependent:
> - chains
> - "chains_config[item.0].configs"
>
> Cheers,
> Felix
>
>
>
> > 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].
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/b5b83bee-9ac0-4d6b-9d77-f687ba1775c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.