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