role dependencies - path to parent role's templates folder

63 views
Skip to first unread message

ProfHase

unread,
May 25, 2016, 10:43:22 AM5/25/16
to Ansible Project
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?

Johannes Kastl

unread,
May 25, 2016, 11:23:03 AM5/25/16
to ansible...@googlegroups.com
On 25.05.16 16:43 ProfHase wrote:

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

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

signature.asc

ProfHase

unread,
May 30, 2016, 8:03:52 AM5/30/16
to Ansible Project
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

Johannes Kastl

unread,
May 30, 2016, 8:38:27 AM5/30/16
to ansible...@googlegroups.com
On 30.05.16 14:03 ProfHase wrote:
> 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)

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

signature.asc
Reply all
Reply to author
Forward
0 new messages