role dependencies - path to parent role's templates folder

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?

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

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

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

dependencies:
  - { 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