# Add role dependency to another role without it being executed automatically

**URL:** <https://forum.ansible.com/t/add-role-dependency-to-another-role-without-it-being-executed-automatically/24929>\
**Category:** Ansible Project\
**Created:** [July 7, 2017, 7:08pm UTC](https://forum.ansible.com/t/add-role-dependency-to-another-role-without-it-being-executed-automatically/24929 "2017-07-07T19:08:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Connell](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@Lee\_Connell](https://forum.ansible.com/u/Lee_Connell)\
**Post date:** [July 7, 2017, 7:08pm UTC](https://forum.ansible.com/t/add-role-dependency-to-another-role-without-it-being-executed-automatically/24929/1 "2017-07-07T19:08:06Z")

</div>

Hi all,

I have a role that has a dependency on another role, however by default, Ansible will execute the dependency first. In my case, I do not want this to happen. I don’t want the role executed automatically at all. The role that is requiring this dependency will call it on its own within it’s own tasks. Right now, I am checking if a variable is defined, and if it is, then the tasks within the dependent role will run, but you still see the task line item in the playbook output. I would like to avoid it attempting to execute it altogether.

[https://gist.github.com/lconnell/dfb1dc5383517b3bdd9c4832ae9027e2](https://gist.github.com/lconnell/dfb1dc5383517b3bdd9c4832ae9027e2)

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [July 7, 2017, 8:22pm UTC](https://forum.ansible.com/t/add-role-dependency-to-another-role-without-it-being-executed-automatically/24929/2 "2017-07-07T20:22:06Z")

</div>

It doesn't sound like you want a dependency at all.

Why not just stick the slack tasks in the relevant roles?  
You're losing a lot of clarity trying to use a role to save a bit  
of typing, and from the look of that gist you aren't even saving  
much typing 🙂

---

<div class="post-metadata">

**Author:** ![Lee\_Connell](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@Lee\_Connell](https://forum.ansible.com/u/Lee_Connell)\
**Post date:** [July 9, 2017, 4:06pm UTC](https://forum.ansible.com/t/add-role-dependency-to-another-role-without-it-being-executed-automatically/24929/3 "2017-07-09T16:06:50Z")

</div>

I agree, I’m going to move them into the roles, especially since the slack role doesn’t really accomplish much.

With that being said, say the dependent role was a bunch of API calls to accomplish some task. In this case, I could call include role and call for a particular task within that role.

If I added it as a dependency to my calling role, I would end up in the same position. Am I just using Ansible and roles, the wrong way here?

How can you add a role as a dependency without it being called by default? Seems like that isn’t possible. Any alternative approaches?

Thanks for your response 🙂

---

<div class="post-metadata">

**Author:** ![drybjed](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@drybjed](https://forum.ansible.com/u/drybjed)\
**Post date:** [July 9, 2017, 4:09pm UTC](https://forum.ansible.com/t/add-role-dependency-to-another-role-without-it-being-executed-automatically/24929/4 "2017-07-09T16:09:23Z")

</div>

Just add it in the playbook. Ansible reads all roles on the playbook level and includes their variables, the same as a role dependency in `meta/main.yml`. That way you can run the specific roles using tags without executing the dependencies as well.

---

<div class="post-metadata">

**Author:** ![Lee\_Connell](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@Lee\_Connell](https://forum.ansible.com/u/Lee_Connell)\
**Post date:** [July 9, 2017, 6:45pm UTC](https://forum.ansible.com/t/add-role-dependency-to-another-role-without-it-being-executed-automatically/24929/5 "2017-07-09T18:45:19Z")

</div>

Right, that’s what I was originally doing and works just fine. My thought process whas to add it as a dependency so it would get installed via the galaxy command automatically. Without the role added as a dependency, it will need to be a manual process.

Thanks!
