VikingPingvin
VikingPingvin

Reputation: 392

Sensible way to have a common set of roles as base for multiple playbooks in ansible?

I use ansible to manage a wide range of VMs, all with their own specifics, but each have some roles commonly defined under them.

Eg. multiple playbooks reference a role, that sets up admin users with access, same goes for ssh setup, timesync, timezone etc.

Now these roles are explicitly referenced in the same way in these playbooks, which is hard to maintain if a role happens to change.

I tried two methods:

If anyone more experienced, is there a suggested way to group commonly used roles together while still having the option to use the separately if needed?

Upvotes: 0

Views: 150

Answers (1)

zenlord
zenlord

Reputation: 340

I would not want to say that I'm more experienced, but I do have a way of 'making it work for me', and am also struggling with the question if this is the best (or at least a good) way of doing it.

  • My hosts are divided in groups, and each group has it own set of variables in group_vars.
  • I have a single playbook for each top-level group ("server" and "client").
  • The roles are split up according to function ("webserver" or "gnome-desktop").
  • Whenever a role is used by multiple hosts or groups, I use conditionals based on inventory_hostname, groups or a custom variable. This does generate some repetition, but that can be kept minimal by conditionally importing tasks.

To be completely honest: I'm not there yet, but in a few weekends from now I hope to get there :-).

Upvotes: 1

Related Questions