# How to pass a variable to a filter plugin ?

**URL:** <https://forum.ansible.com/t/how-to-pass-a-variable-to-a-filter-plugin/20105>\
**Category:** Ansible Project\
**Created:** [December 31, 2015, 7:01pm UTC](https://forum.ansible.com/t/how-to-pass-a-variable-to-a-filter-plugin/20105 "2015-12-31T19:01:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustavo\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/g/45deac/32.png) [@Gustavo\_Aguiar](https://forum.ansible.com/u/Gustavo_Aguiar)\
**Post date:** [December 31, 2015, 7:01pm UTC](https://forum.ansible.com/t/how-to-pass-a-variable-to-a-filter-plugin/20105/1 "2015-12-31T19:01:12Z")

</div>

Hi All,

First of all, Happy New Year to everybody. 🙂

I would like to know if it is possible to pass a variable to a filter.

I have this code that works with a predefined text:

"{{ ec2\_vpc\_out.subnets | get\_subnets(‘Name’, ’TheName’) | first }}”

Now I need to replace the ‘TheName’ argument with a variable. E.g.:

"{{ ec2\_vpc\_out.subnets | get\_subnets(‘Name’, \<item.name\>) | first }}”

Is there a way of doing this ?

Thanks,  
Gustavo Aguiar

---

<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:** [January 1, 2016, 5:36am UTC](https://forum.ansible.com/t/how-to-pass-a-variable-to-a-filter-plugin/20105/2 "2016-01-01T05:36:13Z")

</div>

It should be this simple:

"{{ ec2\_vpc\_out.subnets | get\_subnets('Name', item.name) | first }}”

---

<div class="post-metadata">

**Author:** ![Gustavo\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/g/45deac/32.png) [@Gustavo\_Aguiar](https://forum.ansible.com/u/Gustavo_Aguiar)\
**Post date:** [January 4, 2016, 2:57pm UTC](https://forum.ansible.com/t/how-to-pass-a-variable-to-a-filter-plugin/20105/3 "2016-01-04T14:57:08Z")

</div>

Thank you Brian! I was adding the ’ and this was breaking my tests…

Thanks again,  
—Gustavo
