On 12/2/20 2:41 PM, Daniel Caillibaud wrote:
> Hi,
>
> I saw the dict2items filter, which can be use with
>
> # with this var
> ips:
> foo: 192.168.1.4
> bar: 1.2.3.4
>
> # a task with a loop on it
> debug:
> msg: "here is an ip {{ item.value }}
> loop: "{{ ips | dict2items | list }}"
>
> When only keys or values are needed, the use of .keys() or .values() seems
> easier (especially with filters)
>
> debug:
> msg: "here is a private ip {{ item }}"
> loop: "{{ ips.values() | list | ipaddr('private') | default('') }}"
>
> but I didn't find any mention of this in the official doc, neither in the
> examples I saw, is it better to avoid this way of looping ?
>
In my opinion it is fine to use the methods of the underlying Python objects.
In some cases it is hard to solve without that, especially with
nested variables:
Environment="FCGI_CHILDREN={{ sympa.web.get(unit_name + '_procs') }}"
Regards
Racke
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.