Sharing tasks between roles

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 ?

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”

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