something like:

 - name: find another host to join to form a cluster (e.g. Consul)
   set_fact:
     host_to_join: >
     {{
       (groups['my_group'] | difference([inventory_hostname])
                          | random
                          | intersection(hostvars.keys())
).'ec2_private_ip_address'
     }}

On Tue, Jul 7, 2015 at 6:39 AM, Valentin Fadeev
<[email protected]> wrote:
> Recently I had to write templates containing somewhat long filter pipelines.
> Part of the logic involved lookuping current output of the pipeline in a
> dictionary (hostvars) and then extracting the value of a field of the
> resulting dictionary. In order to keep things decoupled I wrote two almost
> trivial plugins. Here an example:
>
>  - name: find another host to join to form a cluster (e.g. Consul)
>    set_fact:
>      host_to_join: >
>      {{
>        groups['my_group'] | difference([inventory_hostname])
>                           | list
>                           | random
>                           | find_in(hostvars)
>                           | get_key('ec2_private_ip_address')
>      }}
>
> Just wondering whether there are other existing ways of achieving the same
> result, with/without plugins, as surely someone must have faced a similar
> task.
>
> Thanks
> Valentin
>
> --
> 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/0b9c36de-08e3-41df-a21c-1d2e8df19e1b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Brian Coca

-- 
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/CAJ5XC8kd3S_%3D-jyZLa2-x0fAkE%2B-V6Psu-u%3Dn83KN9eDiywG4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to