# matching on facts in templates

**URL:** <https://forum.ansible.com/t/matching-on-facts-in-templates/16411>\
**Category:** Ansible Project\
**Created:** [October 2, 2014, 10:39pm UTC](https://forum.ansible.com/t/matching-on-facts-in-templates/16411 "2014-10-02T22:39:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barry\_Morrison](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@Barry\_Morrison](https://forum.ansible.com/u/Barry_Morrison)\
**Post date:** [October 2, 2014, 10:39pm UTC](https://forum.ansible.com/t/matching-on-facts-in-templates/16411/1 "2014-10-02T22:39:44Z")

</div>

I have some legacy servers, and I have some servers that aren’t legacy and being built a new way with new network interfaces.

The playbook/template worked matching on the old template and facts, but now that a new interface exists, I need to see if it it exists, and if it does, use it.

I’ve got this [https://gist.github.com/esacteksab/b1b2439fa6acb68dfc1e](https://gist.github.com/esacteksab/b1b2439fa6acb68dfc1e)

And errors but -vvvv isn’t clear what host(s) it’s failing on.

Is this supported in the template? Is the matching correct as far as hostvars[host][‘ansible\_br305’] or is there some other way to get at facts in a template?

Thanks!

---

<div class="post-metadata">

**Author:** ![Barry\_Morrison](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@Barry\_Morrison](https://forum.ansible.com/u/Barry_Morrison)\
**Post date:** [October 2, 2014, 11:13pm UTC](https://forum.ansible.com/t/matching-on-facts-in-templates/16411/2 "2014-10-02T23:13:22Z")

</div>

I needed

{% if ‘ansible\_br305’ in hostvars[hosts] %} and it works!

Thanks.
