# Filtering on a Template variable

**URL:** <https://forum.ansible.com/t/filtering-on-a-template-variable/25327>\
**Category:** Ansible Project\
**Created:** [August 25, 2017, 3:08am UTC](https://forum.ansible.com/t/filtering-on-a-template-variable/25327 "2017-08-25T03:08:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [August 25, 2017, 3:08am UTC](https://forum.ansible.com/t/filtering-on-a-template-variable/25327/1 "2017-08-25T03:08:57Z")

</div>

How can I filter a variable in a template so that I can extract a fact

Trying to get the default ipv4 address from a template

template.j2  
ipv4 address ((ansible\_default\_ipv4 | grep address}}

A similar format will work via command line but not via a template. Whats the correct formatting required to do something like that via template?

Thanks

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 25, 2017, 7:20am UTC](https://forum.ansible.com/t/filtering-on-a-template-variable/25327/2 "2017-08-25T07:20:01Z")

</div>

ipv4 address {{ ansible\_default\_ipv4.address }}

---

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [August 25, 2017, 7:50pm UTC](https://forum.ansible.com/t/filtering-on-a-template-variable/25327/3 "2017-08-25T19:50:38Z")

</div>

That works thanks. I suppose what confused me a little was when trying to do this via command line I had to use grep…

[ansible@localhost exercises]$ ansible local -m setup -a ‘filter=ansible\_default\_ipv4\*’ | grep address
