How to share template between two roles?

Roles are intended to be independent things, so sharing files between them doesn’t make a lot of sense. One thing you could do, if these two roles are that similar, is to combine them into a single role and add a variable to defaults which set the mode, for instance “dbservers_mode: master”. Then you could have something like this in your tasks/main.yml:

  • include: “{{dbservers_mode}}.yml”

And then the master.yml/slave.yml files would be the tasks/main.yml from each of the individual roles.

Hope that helps!