Reputation: 1174
I've started out using ansible and I'm wondering what the best practice is for using multiple roles in a playbook or specifying multiple role dependencies. Example: consider a role name common
. This role exists to share common config across all things in the site. Then there are roles like web
, db
, or mail
etc. In practice these require the common
role. So the question is: Should such a thing be expressed in a playbook that creates machines for the different roles or specified as role dependencies? Is there any trade-offs which one approach or the other. I lean towards specifying them as role dependencies.
How have you done it before?
Upvotes: 2
Views: 2766
Reputation: 59989
A role dependency is appropriate if a role really is depending on that other role, like installing some requirements first, before they can be used etc. So if common
indeed installs requirements then it qualifies for a role dependency. It should not be a role dependency if it does completely unrelated things.
The name common
suggests it might actually be doing multiple things that just happen to be executed on all hosts. Instead I suggest you really think in roles. All hosts might have Apache, MySQL and PHP installed. That does not mean it all has to be stuffed into a single role. Make it 3 roles, small packages. It then should get obvious which role is a dependency of another role or if it should be added on the playbook level.
Upvotes: 2