# Sharing tasks between roles

**URL:** <https://forum.ansible.com/t/sharing-tasks-between-roles/13784>\
**Category:** Ansible Project\
**Created:** [October 28, 2013, 12:06am UTC](https://forum.ansible.com/t/sharing-tasks-between-roles/13784 "2013-10-28T00:06:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francois\_Durand](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@Francois\_Durand](https://forum.ansible.com/u/Francois_Durand)\
**Post date:** [October 28, 2013, 12:06am UTC](https://forum.ansible.com/t/sharing-tasks-between-roles/13784/1 "2013-10-28T00:06:59Z")

</div>

Hi,

I’d like to have all instances be installed with a set of common packages (common role), an then each role installed with its own specific set of packages.

I’d like to code the package installation tasks only once (it could be apt-get update + apt-get install, or download + install, or git clone + make install).

I’ve thought about several bad solutions:

- all install tasks are in common role, package list vars are defined in common role too, but specific roles can “enrich” them with additional packages to install.  
problems:

- I never tried to enrich variables, not sure it works, order of parsing may also break it
- tasks must handle the fact that the package list variable could be empty

- installation tasks are roles, other roles use dependencies  
problems:

- only one role of a set of roles used by a playbook can use an install role =\> not sharing it with common, for instance

- using an include from a folder outside roles  
problem:

- needs to use a few …/… to get to the shared folder

any other idea ?

---

<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:** [October 28, 2013, 12:27pm UTC](https://forum.ansible.com/t/sharing-tasks-between-roles/13784/2 "2013-10-28T12:27:45Z")

</div>

You could use parameterized task includes, but really these are so short they probably shouldn’t even be split out.

I don’t know what you mean by “enriching variables”

---

<div class="post-metadata">

**Author:** ![Francois\_Durand](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@Francois\_Durand](https://forum.ansible.com/u/Francois_Durand)\
**Post date:** [November 9, 2013, 11:27pm UTC](https://forum.ansible.com/t/sharing-tasks-between-roles/13784/3 "2013-11-09T23:27:10Z")

</div>

I have a common role giving a list of packages to install.  
Then each specialized role may add other packages to that list.  
However I’d like to define how to install all those packages in only one place.

For instance how would you design something like this:

roles/common/vars/main.yml
