# role dependencies - path to parent role's templates folder

**URL:** <https://forum.ansible.com/t/role-dependencies-path-to-parent-roles-templates-folder/21565>\
**Category:** Ansible Project\
**Created:** [May 25, 2016, 2:43pm UTC](https://forum.ansible.com/t/role-dependencies-path-to-parent-roles-templates-folder/21565 "2016-05-25T14:43:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [May 25, 2016, 2:43pm UTC](https://forum.ansible.com/t/role-dependencies-path-to-parent-roles-templates-folder/21565/1 "2016-05-25T14:43:22Z")

</div>

I am deploying multiple web applications that all have 4 tasks in common:

`

- name: copy nginx conf  
template:  
src=nginx.conf  
dest=/etc/nginx/{{ inventory\_hostname }}.conf

- enable nginx conf  
file:  
state=link  
…

- name: copy certs  
…

- name: copy chain  
…

`

To avoid this redundancy, I tried to define a meta role: `nginx` with the tasks above and set this role as dependency in every webapp role

`

# webapp1-role meta/main.yml

dependencies: {name: nginx, tags: [nginx]}

`

Unfortunately the nginx role does not search in `templates` folder of the `webapp1-role`

Does the `nginx` role somehow know about the role it is called with?  
Or how would I prevent this redundancy?

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 25, 2016, 3:22pm UTC](https://forum.ansible.com/t/role-dependencies-path-to-parent-roles-templates-folder/21565/2 "2016-05-25T15:22:49Z")

</div>

Maybe you can give a relative path to the template module. So from  
your role nginx you need to set a path something like this:

template: src=../webapp1-role/templates/foobar

Johannes

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [May 30, 2016, 12:03pm UTC](https://forum.ansible.com/t/role-dependencies-path-to-parent-roles-templates-folder/21565/3 "2016-05-30T12:03:52Z")

</div>

Thanks Johannes,  
the problem about it is: There is no way to pass the role path of the `webapp1-role` to the `nginx` role ( I’d rather not hardcode it, so that I could use nginx as dependence for multiple roles)  
The  
`  
{{ role\_path }}

`

always resolves to the nginx role

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 30, 2016, 12:38pm UTC](https://forum.ansible.com/t/role-dependencies-path-to-parent-roles-templates-folder/21565/4 "2016-05-30T12:38:10Z")

</div>

You can't? At least it does for me:

dependencies:  
&nbsp;&nbsp;- { role: foobar, my\_variable: whatever }

That way you can include a fail task in your nginx role (to fail when  
the variable is not set) and use the variable as path to the file.  
Untested...

Johannes
