# Problem accessing variables in nested templates

**URL:** <https://forum.ansible.com/t/problem-accessing-variables-in-nested-templates/14816>\
**Category:** Ansible Project\
**Created:** [March 20, 2014, 8:49pm UTC](https://forum.ansible.com/t/problem-accessing-variables-in-nested-templates/14816 "2014-03-20T20:49:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eoblar](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@eoblar](https://forum.ansible.com/u/eoblar)\
**Post date:** [March 20, 2014, 8:49pm UTC](https://forum.ansible.com/t/problem-accessing-variables-in-nested-templates/14816/1 "2014-03-20T20:49:13Z")

</div>

I’m trying to use ansible to generate a file using nested templates, and I’m running into issues with  
having the variables available to me in the nested templates. I’ll try to explain this concisely.

File ./hosts.yml:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 21, 2014, 12:39pm UTC](https://forum.ansible.com/t/problem-accessing-variables-in-nested-templates/14816/2 "2014-03-21T12:39:40Z")

</div>

What version of jinja2 are you running?

According to the docs[1], as of 2.1 this should work. Something else to try would be something like:

> {% include incfile with context %}

Not sure if something would be disabling context, so maybe this would override that if that is indeed the problem.

[1] [http://jinja.pocoo.org/docs/templates/#import-context-behavior](http://jinja.pocoo.org/docs/templates/#import-context-behavior)

---

<div class="post-metadata">

**Author:** ![eoblar](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@eoblar](https://forum.ansible.com/u/eoblar)\
**Post date:** [March 21, 2014, 12:53pm UTC](https://forum.ansible.com/t/problem-accessing-variables-in-nested-templates/14816/3 "2014-03-21T12:53:49Z")

</div>

Running ansible 1.5 with Jinja2 2.7.2 on Debian 7. I should have mentioned - I did try the ‘with context’ change, but it made no difference.
