# Filter plugins

**URL:** <https://forum.ansible.com/t/filter-plugins/18698>\
**Category:** Ansible Project\
**Created:** [July 7, 2015, 10:39am UTC](https://forum.ansible.com/t/filter-plugins/18698 "2015-07-07T10:39:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valentin\_Fadeev](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@Valentin\_Fadeev](https://forum.ansible.com/u/Valentin_Fadeev)\
**Post date:** [July 7, 2015, 10:39am UTC](https://forum.ansible.com/t/filter-plugins/18698/1 "2015-07-07T10:39:50Z")

</div>

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](https://gist.github.com/ValFadeev/9bf421fc1262c9ec7e31). 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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 7, 2015, 3:16pm UTC](https://forum.ansible.com/t/filter-plugins/18698/2 "2015-07-07T15:16:44Z")

</div>

something like:

- name: find another host to join to form a cluster (e.g. Consul)  
&nbsp;&nbsp;&nbsp;set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host\_to\_join: \>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(groups['my\_group'] | difference([inventory\_hostname])  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\> random  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\> intersection(hostvars.keys())  
).'ec2\_private\_ip\_address'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}
