# template import from outside of templates dir

**URL:** <https://forum.ansible.com/t/template-import-from-outside-of-templates-dir/17505>\
**Category:** Ansible Project\
**Created:** [February 11, 2015, 7:11pm UTC](https://forum.ansible.com/t/template-import-from-outside-of-templates-dir/17505 "2015-02-11T19:11:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacob\_Weber1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jacob\_Weber1](https://forum.ansible.com/u/Jacob_Weber1)\
**Post date:** [February 11, 2015, 7:11pm UTC](https://forum.ansible.com/t/template-import-from-outside-of-templates-dir/17505/1 "2015-02-11T19:11:08Z")

</div>

One of my roles uses a template, which has an {% import … %} statement to include data from another template.

I’d like this other template to be outside of the role’s “templates” directory, since it will be shared by multiple roles.

If I try including a relative path:  
{% import …/…/…/foo.j2 as foo with context %}  
it fails with the error “Cannot find/not allowed to load (include) template”. I think this is because Jinja2 won’t include paths with “…” in them.

But it also fails if I include an absolute path, using playbook\_dir:

{% import playbook\_dir ~ ‘/foo.j2’ as foo with context %}

Why would that second version fail? Is there another way to do this?

Thanks,  
Jacob

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 13, 2015, 1:59am UTC](https://forum.ansible.com/t/template-import-from-outside-of-templates-dir/17505/2 "2015-02-13T01:59:01Z")

</div>

The "template" plugin will use the runner's basedir, so try to specify a  
path relative to the playbook's directory.

Giovanni

---

<div class="post-metadata">

**Author:** ![Jacob\_Weber1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jacob\_Weber1](https://forum.ansible.com/u/Jacob_Weber1)\
**Post date:** [February 13, 2015, 3:05am UTC](https://forum.ansible.com/t/template-import-from-outside-of-templates-dir/17505/3 "2015-02-13T03:05:53Z")

</div>

Thanks – that worked, e.g.:

{% import ‘roles/other\_role/templates/foo.j2’ as foo with context %}

Jacob
