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

**URL:** <https://forum.ansible.com/t/is-it-possible-for-a-task-to-use-a-different-template-depending-of-the-role/14541>\
**Category:** Ansible Project\
**Created:** [February 11, 2014, 4:57pm UTC](https://forum.ansible.com/t/is-it-possible-for-a-task-to-use-a-different-template-depending-of-the-role/14541 "2014-02-11T16:57:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [February 11, 2014, 4:57pm UTC](https://forum.ansible.com/t/is-it-possible-for-a-task-to-use-a-different-template-depending-of-the-role/14541/1 "2014-02-11T16:57:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Walid](https://avatars.discourse-cdn.com/v4/letter/w/ea5d25/32.png) [@Walid](https://forum.ansible.com/u/Walid)\
**Post date:** [February 11, 2014, 5:34pm UTC](https://forum.ansible.com/t/is-it-possible-for-a-task-to-use-a-different-template-depending-of-the-role/14541/2 "2014-02-11T17:34:35Z")

</div>

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
