Role within role syntax

Hi

I am working on this role:

https://github.com/DevOps4Networks/ansible-opendaylight-devtools

Within which I would like to use this role:

https://github.com/William-Yeh/ansible-oracle-java

I have tried adding the role via an include in this file:

https://github.com/DevOps4Networks/ansible-opendaylight-devtools/blob/master/tasks/main.yml

To this file:

https://github.com/DevOps4Networks/ansible-opendaylight-devtools/blob/master/tasks/install_jdk8.yml

Which has:

To have roles use other roles, use role dependencies http://docs.ansible.com/ansible/playbooks_roles.html#role-dependencies

Many thanks :slight_smile:

The order is such that the dependencies are executed *first*, which is to say that the role that is defined as having the dependency on the other roles requires that the other roles have been executed first.

This makes sense, given what is implied by the meaning of dependency.

Is there also a mechanism to have other roles executed *after*?

Regards

Nathan

Hi,

In Ansible you can’t ‘call’ roles from roles whenever you want - you can just have dependencies that are executed before your role. What we do in such cases is to have one orchestration role that doesn’t do anything else than depending on multiple roles in the right order.
Alternatively, you can handle that on a play level by including roles in the right order and documenting that for your users but this adds a bit of code duplication and complexity.

-ibratoev

Many thanks for this. I like the idea of a “coordinating” role.

Regards

Nathan

Hello,

I am also interested on this subject. I am also having a need to have a role within a role and I don’t know how to properly achieve that. I am looking forward to create atomic roles (with “unit testing” using travis) that are grouped within a bigger role-group (that could be also tested), which are then included in a bigger all-in-one role (that could be also tested).

Any example of roles within roles that could be shared please?

Thank you very much.