# Included playbook from a role can not find it's template files

**URL:** <https://forum.ansible.com/t/included-playbook-from-a-role-can-not-find-its-template-files/28102>\
**Category:** Ansible Project\
**Created:** [July 20, 2018, 1:36am UTC](https://forum.ansible.com/t/included-playbook-from-a-role-can-not-find-its-template-files/28102 "2018-07-20T01:36:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![igorc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/igorc/32/5491_2.png) [@igorc](https://forum.ansible.com/u/igorc)\
**Post date:** [July 20, 2018, 1:36am UTC](https://forum.ansible.com/t/included-playbook-from-a-role-can-not-find-its-template-files/28102/1 "2018-07-20T01:36:39Z")

</div>

Hi,

Consider I have the following structure under a current directory:

`  
.

> playbook.yml  
> ├── roles  
> │ ├── common  
> │ │ ├── defaults  
> │ │ ├── files  
> │ │ ├── handlers  
> │ │ ├── tasks  
> │ │ ├── templates  
> │ │ └── vars

`

The playbook.yml includes a playbook from the common role like this:

`

- hosts: “{{ hosts }}”  
tasks:
- include: roles/common/tasks/task.yml  
`

This task from the role installs template on the target host as follows:

`

- template: src=file.j2 dest=/usr/local/etc/file owner=root group=root mode=0644  
`

This worked without issues on 1.9.4. Now after upgrade to 2.1.6 I get an error:

`fatal: [IP]: FAILED! => {"changed": false, "failed": true, "msg": "IOError: [Errno 2] No such file or directory: u'/current/directory/path/file.j2'"}`

So, looks like something has changed in the way Ansible looks for files referenced by an included task. It used to look inside the role’s directory where the task was included from but now it searches in the local directory where the calling playbook is executed from.

This looks counter intuitive and prevents from role tasks being re-used in other playbooks outside the role itself.

Is this a bug or know regression in 2.1.x or “works by design”? Is this happening in 2.1.x only?

Thanks,  
Igor

---

<div class="post-metadata">

**Author:** ![igorc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/igorc/32/5491_2.png) [@igorc](https://forum.ansible.com/u/igorc)\
**Post date:** [July 20, 2018, 2:12am UTC](https://forum.ansible.com/t/included-playbook-from-a-role-can-not-find-its-template-files/28102/2 "2018-07-20T02:12:40Z")

</div>

By the way, using relative path to the template in the included role task:

`

`

- template: src=“…/templates/file.j2” dest=/usr/local/etc/file owner=root group=root mode=0644  
`

`

doesn’t help either, in this case Ansible looks for templates dir under the home of the user executing the playbook:

`  
fatal: [IP]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “IOError: [Errno 2] No such file or directory: u’/home/user/templates/file.j2’”}

`

Have tried setting ansible\_search\_path var too but that doesn’t help either.

Any other ideas?

---

<div class="post-metadata">

**Author:** ![mhalano](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mhalano/32/1815_2.png) [@mhalano](https://forum.ansible.com/u/mhalano)\
**Post date:** [July 20, 2018, 6:54pm UTC](https://forum.ansible.com/t/included-playbook-from-a-role-can-not-find-its-template-files/28102/3 "2018-07-20T18:54:21Z")

</div>

May be you could try “import\_tasks” instead of a include?
