# Skipping a role makes it skip all dependencies

**URL:** <https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788>\
**Category:** Ansible Project\
**Created:** [July 28, 2014, 5:03am UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788 "2014-07-28T05:03:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@John\_Anderson](https://forum.ansible.com/u/John_Anderson)\
**Post date:** [July 28, 2014, 5:03am UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/1 "2014-07-28T05:03:42Z")

</div>

So if I have a role with this as their meta:

---

<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:** [July 28, 2014, 2:06pm UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/2 "2014-07-28T14:06:05Z")

</div>

The “when” conditional is properly being applied to both tasks in this scenario, by design.

This seems like the most logical behavior, because the parent role has decided to not be included, so the dependencies should have the same conditions.

---

<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:** [July 28, 2014, 2:06pm UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/3 "2014-07-28T14:06:21Z")

</div>

Also, this is not an inheritance model. This is a dependency model.

---

<div class="post-metadata">

**Author:** ![John\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@John\_Anderson](https://forum.ansible.com/u/John_Anderson)\
**Post date:** [July 29, 2014, 2:19pm UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/4 "2014-07-29T14:19:57Z")

</div>

Maybe I’m misunderstanding the dependency model if the current way is working in the most logical way. I consider  
roles as jobs and tasks as things the job needs to do.

If I have two jobs: being a parent and a restaurant cook, one of the tasks of both of these jobs is doing the dishes. If I  
stop being a restaurant cook this doesn’t mean I get to stop doing dishes as a parent.

Would love to understand this model more and why skipping a role would mean that any others roles who have explicitly  
defined dependencies would be ignored.

A more real world example of my problem is we are experimenting with both gunicorn and uwsgi and so depending on some  
facts gathered we want to install one or the other:

- [surveymonkey.com](http://surveymonkey.com)

- {role: gunicorn, when use\_gunicorn=true }

- {role: uwsgi, when not use\_gunicorn=true }

- gunicorn

- { role: python }

- uwsgi

- { role: python }

So in this use case, when we decided a specific server should be uwsgi ansible has decided that uwsgi doesn’t depend on python because gunicorn depended on it and we don’t want to be a gunicorn server.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [July 29, 2014, 2:31pm UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/5 "2014-07-29T14:31:10Z")

</div>

> If I have two jobs: being a parent and a restaurant cook, one of the tasks  
> of both of these jobs is doing the dishes. If I  
> stop being a restaurant cook this doesn't mean I get to stop doing dishes  
> as a parent.

​Yes, but you probably will have other tools as a cook and as a parent.  
Parameters differ. You also do that in other locations.  
So, in this example, you would have to do it twice: at work and at home,  
each with their specific parameters,

> Would love to understand this model more and why skipping a role would  
> mean that any others roles who have explicitly  
> defined dependencies would be ignored.

​So in this case, one of the parameters is a conditional that should not  
apply to the other case. So you need to have this dependency as a double,  
separate dependency with their won parameters.

Which means you need to allow duplicates.

&nbsp;&nbsp;Serge

---

<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:** [July 29, 2014, 2:48pm UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/6 "2014-07-29T14:48:55Z")

</div>

In your original note:

---

<div class="post-metadata">

**Author:** ![John\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@John\_Anderson](https://forum.ansible.com/u/John_Anderson)\
**Post date:** [July 29, 2014, 4:05pm UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/7 "2014-07-29T16:05:57Z")

</div>

The problem is the role is higher level, these roles are never declared in the playbook. The full set looks like this:

They playbook:

# surveymonkey.yml

- hosts: “auth\_web\_servers”  
roles:

- usersvc

- hosts: “main\_web\_servers”  
roles:

- surveymonkey

and then those roles:

# roles/usersvc/meta/main.yml

dependencies:

- { role: gunicorn, when: use\_uwsgi is not defined }
- { role: uwsgi, when: use\_uwsgi is defined }

# roles/surveymonkey/meta/main.yml

dependencies:

- { role: gunicorn, when: use\_uwsgi is not defined }
- { role: uwsgi, when: use\_uwsgi is defined }

# roles/gunicorn/meta/main.yml

dependencies:

- { role: python }

# roles/uwsgi/meta/main.yml

dependencies:

- { role: python }

Are you saying I can declare roles inside meta/main.yml instead of 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:** [July 29, 2014, 8:59pm UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/8 "2014-07-29T20:59:32Z")

</div>

Nope, just saying that was a quicker problem.

It seems you are modelling role dependencies a bit heavy. People will disagree, and they silenced some important concerns from people who really felt they needed them, but I actually encourage not using role deps for most cases.

What Serge said above about enabling duplicates should resolve your question.

---

<div class="post-metadata">

**Author:** ![John\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@John\_Anderson](https://forum.ansible.com/u/John_Anderson)\
**Post date:** [July 29, 2014, 10:42pm UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/9 "2014-07-29T22:42:14Z")

</div>

Yeah, duplicates is how I solved my problem in the short term but this made it so my roles run tons of times and it slows my script down by an hour because some of my roles that would need to be marked as duplicates are all the common things that can be inherited but only ran once, so things like checking if there is a new version in git, installing common packages etc.

---

<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:** [July 30, 2014, 11:49am UTC](https://forum.ansible.com/t/skipping-a-role-makes-it-skip-all-dependencies/15788/10 "2014-07-30T11:49:32Z")

</div>

I seriously suspect you don’t need role dependencies.

Just put the things in your roles you need, or call setup roles before other roles.
