# Role within role syntax

**URL:** <https://forum.ansible.com/t/role-within-role-syntax/19523>\
**Category:** Ansible Project\
**Created:** [October 16, 2015, 1:13pm UTC](https://forum.ansible.com/t/role-within-role-syntax/19523 "2015-10-16T13:13:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Sowatskey](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@Nathan\_Sowatskey](https://forum.ansible.com/u/Nathan_Sowatskey)\
**Post date:** [October 16, 2015, 1:13pm UTC](https://forum.ansible.com/t/role-within-role-syntax/19523/1 "2015-10-16T13:13:11Z")

</div>

Hi

I am working on this role:

[https://github.com/DevOps4Networks/ansible-opendaylight-devtools](https://github.com/DevOps4Networks/ansible-opendaylight-devtools)

Within which I would like to use this role:

[https://github.com/William-Yeh/ansible-oracle-java](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](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](https://github.com/DevOps4Networks/ansible-opendaylight-devtools/blob/master/tasks/install_jdk8.yml)

Which has:

| |

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 17, 2015, 3:59am UTC](https://forum.ansible.com/t/role-within-role-syntax/19523/2 "2015-10-17T03:59:40Z")

</div>

To have roles use other roles, use role dependencies [http://docs.ansible.com/ansible/playbooks\_roles.html#role-dependencies](http://docs.ansible.com/ansible/playbooks_roles.html#role-dependencies)

---

<div class="post-metadata">

**Author:** ![Nathan\_Sowatskey](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@Nathan\_Sowatskey](https://forum.ansible.com/u/Nathan_Sowatskey)\
**Post date:** [October 17, 2015, 8:13am UTC](https://forum.ansible.com/t/role-within-role-syntax/19523/3 "2015-10-17T08:13:40Z")

</div>

Many thanks 🙂

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

---

<div class="post-metadata">

**Author:** ![Ivaylo\_Bratoev](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ivaylo\_Bratoev](https://forum.ansible.com/u/Ivaylo_Bratoev)\
**Post date:** [October 17, 2015, 8:33am UTC](https://forum.ansible.com/t/role-within-role-syntax/19523/4 "2015-10-17T08:33:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nathan\_Sowatskey](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@Nathan\_Sowatskey](https://forum.ansible.com/u/Nathan_Sowatskey)\
**Post date:** [October 17, 2015, 11:04am UTC](https://forum.ansible.com/t/role-within-role-syntax/19523/5 "2015-10-17T11:04:15Z")

</div>

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

Regards

Nathan

---

<div class="post-metadata">

**Author:** ![Vonpupp](https://avatars.discourse-cdn.com/v4/letter/v/eada6e/32.png) [@Vonpupp](https://forum.ansible.com/u/Vonpupp)\
**Post date:** [October 18, 2015, 4:47pm UTC](https://forum.ansible.com/t/role-within-role-syntax/19523/6 "2015-10-18T16:47:04Z")

</div>

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.
