How to organize roles with a common set of tasks

Hi,

I’m new to ansible, did a good amount of simple things with it in the last couple of days, but I’m still trying to figure out the best way to do what I need, I have looked at the examples, some are close to it, but not quite.

To simplify say I have N instances, and a number M of services of type T to install.

so those M services are svc-a, svc-b, … svc-h to deploy.

I think this matches well with roles.

So all those services are of type T which means they get deployed the same way and require a common set of tasks, check, notifications

To simplify:

  • deploy a rpm for service svc-a via yum
  • notify deployment for svc-a

So in theory I could duplicate the code in all those roles so that they do the same common set of task but that seems fairly odd.
I assume there is a better way to do that rather than duplicating M times the set of commons tasks but just define a name and call a ‘do those common tasks’

Should this be done via module, a library, something else ?

Note also that I must be able to maintain a configuration file on each instance with that needs me to iterate over all those services of type T. (basically to configure an agent that forward the set of logs for each service). I guess it could be done in reverse with each service declaring the logs that it needs to be forwarded too. But again, not sure of the best way to manage this sort of declaration dependency.

I’m looking for any suggestions here of how to organize something like this. I guess the closest example I have so far might be the ec2 example.

Any tips appreciated,

– stephane