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

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

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?

May be you could try “import_tasks” instead of a include?