# execute role dependencies \_after\_ role

**URL:** <https://forum.ansible.com/t/execute-role-dependencies-after-role/14116>\
**Category:** Ansible Developer\
**Created:** [December 10, 2013, 4:59pm UTC](https://forum.ansible.com/t/execute-role-dependencies-after-role/14116 "2013-12-10T16:59:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [December 10, 2013, 4:59pm UTC](https://forum.ansible.com/t/execute-role-dependencies-after-role/14116/1 "2013-12-10T16:59:58Z")

</div>

As it currently stands, role dependencies are executed prior to the  
role in which they are defined. This is a good feature.

But!

I'm running into the situation where I have a 'common' role that gets  
run after some OS-specific roles -- mainly the OS-specific roles are  
doing the package installation and OS specific configurations and the  
common role is doing everything that is similar between the  
distributions.

It would be great if I could tell the os-specific role to depend on  
the common role, but make the common role execute \_after\_ the  
os-specific role. Does this idea make sense? Would it be a useful  
feature for others? Or should it be solved in a different way with  
re-organizing my roles?

My current implementation just runs the roles in a specific order --  
without any dependencies. It works, just wanted to see if there was a  
way to clean things up.

- James

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 10, 2013, 5:36pm UTC](https://forum.ansible.com/t/execute-role-dependencies-after-role/14116/2 "2013-12-10T17:36:19Z")

</div>

So basically requires: would have a requires\_after: or similar?

Can you give an example of the role names so I can better get a feel for the use case?

Thanks!!!

---

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [December 10, 2013, 6:46pm UTC](https://forum.ansible.com/t/execute-role-dependencies-after-role/14116/3 "2013-12-10T18:46:35Z")

</div>

Michael,

requires\_after sounds like a good name.

Here's the way I have my roles structured:

riak/  
&nbsp;&nbsp;common/  
&nbsp;&nbsp;ubuntu/  
&nbsp;&nbsp;redhat/

I have a group\_by task that runs in a bootstrap role and gives me  
groups based on OS.

Then I apply riak/redhat which should depend on riak/common running  
\_afterwards\_.

- James

---

<div class="post-metadata">

**Author:** ![Maciej\_Gol](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@Maciej\_Gol](https://forum.ansible.com/u/Maciej_Gol)\
**Post date:** [February 20, 2014, 10:13pm UTC](https://forum.ansible.com/t/execute-role-dependencies-after-role/14116/4 "2014-02-20T22:13:28Z")

</div>

That’d be a very useful feature! Currently, it’s possible to declare what roles roleA depends on. But sometimes, when writing isolated modules that constitute to a whole, one would like to express that roleA should depend on roleB and roleC when declaring those. Something named like required\_by, required\_in, required\_before (note that we would like both roleB and roleC to be played before roleA). I think that name required\_after would rather refer to a list of roles that should run before the role the name has been declared in, effectively being a synonym for dependencies.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 21, 2014, 1:06am UTC](https://forum.ansible.com/t/execute-role-dependencies-after-role/14116/5 "2014-02-21T01:06:59Z")

</div>

" think that name required\_after would rather refer to a list of roles that should run before the role the name has been declared in"

after should run before might be a bit confusing 🙂

---

<div class="post-metadata">

**Author:** ![vadimv\_Vatlin](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vadimv\_Vatlin](https://forum.ansible.com/u/vadimv_Vatlin)\
**Post date:** [January 21, 2015, 12:47pm UTC](https://forum.ansible.com/t/execute-role-dependencies-after-role/14116/6 "2015-01-21T12:47:32Z")

</div>

Hello.  
Is any news about this problem ?

---

<div class="post-metadata">

**Author:** ![Clement\_Durand](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@Clement\_Durand](https://forum.ansible.com/u/Clement_Durand)\
**Post date:** [May 18, 2018, 1:02am UTC](https://forum.ansible.com/t/execute-role-dependencies-after-role/14116/7 "2018-05-18T01:02:42Z")

</div>

Hello! I know this thread is old but I am interested and I just got an idea on which I would like your opinion.

In my case, I have a “nginx/proxy” role that creates subdomains proxies to services on my server. I also have a “compose” role that manages those services.  
The “nginx/proxy” gets the list of proxy configs from a variable that is updated by “compose”, which in the present case requires me to explicitly make “compose” run before “nginx/proxy”.

What if I want to use dependencies? I thought that I could separate “compose” in two parts: “compose/services” would manage the services and “compose/proxy” would only update the proxy list. Then I could write that “nginx/proxy” depends on “compose/proxy”.

I do not know if it is clear, if it is really relevant, and if such a workaround actually makes sense and would be usable.

Thank you for your comments 🙂
