# Reverse dependencies injection into roles.

**URL:** <https://forum.ansible.com/t/reverse-dependencies-injection-into-roles/14583>\
**Category:** Ansible Project\
**Created:** [February 17, 2014, 9:25pm UTC](https://forum.ansible.com/t/reverse-dependencies-injection-into-roles/14583 "2014-02-17T21:25:03Z")\
**Posts on this page:** 2\
**Page:** 1

<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 17, 2014, 9:25pm UTC](https://forum.ansible.com/t/reverse-dependencies-injection-into-roles/14583/1 "2014-02-17T21:25:03Z")

</div>

Hey!

I’ve been recently struggling with the following use case:  
A server has to be provisioned with system packages and a new user account using a root account. Afterwards, create a python virtualenv in the new user’s home directory, install packages etc.  
My first, obvious try was to split the above tasks’ list into roles:

- A system\_packages role that would install all system packages
- A user\_account role that would setup a new user, copy keys and whatnot.
- A virtualenv role that would setup the virtualenv for newly created used and whatnot.

An example playbook might look like this:

- host: target  
remote\_user: root  
roles:

- system\_packages

- user\_account

- host: target  
remote\_user: target\_user  
roles:

- virtualenv

The problem begins with the virtualenv role: it requires python-virtualenv system package to be installed, and as such the requirement shouldn’t be included in project’s system requirements (so that the developer is freed from knowing system packages required for a role to work). The target\_user has no sudo access, thus I can’t install the package in the second play, but the first one. Now, since virtualenv requirement is not specified in project’s system requirements, it won’t be installed. I was thinking about creating a dummy role system\_packages that would be dependant on instances of a system\_package role that would install a single system requirement. But here is the blocker: I can declare direct dependencies for a roleA, but I can’t specify in roleB declaration that roleA should also depend on {role: system\_package, package: python-virtualenv}.

What I’m really looking for is a mechanism similar to require\_in that is found in SaltStack. Or even better, has anyone struggled with similar use case and has a neat solution to share?

Cheers

---

<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:** [February 18, 2014, 3:02pm UTC](https://forum.ansible.com/t/reverse-dependencies-injection-into-roles/14583/2 "2014-02-18T15:02:26Z")

</div>

I think I struggled with this as well – check out this thread:

[https://groups.google.com/forum/#!topic/ansible-devel/3nhSJl8hRT0](https://groups.google.com/forum/#!topic/ansible-devel/3nhSJl8hRT0)

Although I didn’t come up with a solution, Michael seemed to be open to the idea at the time. Maybe we should open a feature request on github?

- James
