is it possible for a task to use a different template depending of the role ?

Hi,

I have agent-install.yml that installs our application agent and deploys the agent-config template, since agent-install.yml is shared by many roles it’s located under the common role tasks :

role/common/tasks/agent-install.yml
role/common/template/agent-config.j2

This tasks will be run from many roles by using the “- include: role/common/tasks/agent-install.yml” statement , if the role doesn’t have a specific role config it will use the “default” under the role/common/template/agent-config.j2 but there are many roles that have config’s which are mostly different :

role/A/template/agent-config.j2

role/B/template/agent-config.j2

role/C/template/agent-config.j2

role/D/template/agent-config.j2

Is it possible to use the same agent-install.yml but to deploy the role specific agent-config.j2 template in each case ? if a role doesn’t have agent-config.j2 available then the default one should be deployed.

Regards,
Nicolas.

did you look into the group_vars? for the default template create a variable to specify which template (location/name of of file) under group_vars/all, and if the other templates correspond to different host groups in your inventory then override them in their specific group_var