Role within role syntax

145 views
Skip to first unread message

Nathan Sowatskey

unread,
Oct 16, 2015, 9:13:11 AM10/16/15
to Ansible Project
Hi

I am working on this role:


Within which I would like to use this role:


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


To this file:


Which has:

---
#Use role from: https://github.com/William-Yeh/ansible-oracle-java
roles:
- williamyeh.oracle-java
vars:
java_version: 8

But that ends up saying:

ERROR: expecting dict; got: roles, error in /etc/ansible/roles/opendaylight/tasks/install_jdk8.yml

So, I am left wondering whether this form of role reuse is even possible?

Any input gratefully received.

Many thanks

Nathan

Brian Coca

unread,
Oct 16, 2015, 11:59:54 PM10/16/15
to Ansible Project
To have roles use other roles, use role dependencies http://docs.ansible.com/ansible/playbooks_roles.html#role-dependencies


--
Brian Coca

Nathan Sowatskey

unread,
Oct 17, 2015, 4:13:51 AM10/17/15
to ansible...@googlegroups.com
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
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/NjcBXFNZX0c/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8k1%2Bn9XZ9CK%3D2RFwRYRBuzaxBqVBC0Cf4tCij9da1hACA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Ivaylo Bratoev

unread,
Oct 17, 2015, 4:33:11 AM10/17/15
to Ansible Project
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

Nathan Sowatskey

unread,
Oct 17, 2015, 7:04:25 AM10/17/15
to ansible...@googlegroups.com
Many thanks for this. I like the idea of a “coordinating” role.

Regards

Nathan
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/NjcBXFNZX0c/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ea5f2490-0997-425a-a443-784875486ed2%40googlegroups.com.

Vonpupp

unread,
Oct 18, 2015, 11:43:13 PM10/18/15
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages