# template source file not getting from closest role

**URL:** <https://forum.ansible.com/t/template-source-file-not-getting-from-closest-role/17095>\
**Category:** Ansible Project\
**Created:** [December 18, 2014, 5:46am UTC](https://forum.ansible.com/t/template-source-file-not-getting-from-closest-role/17095 "2014-12-18T05:46:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Kieu](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Steve\_Kieu](https://forum.ansible.com/u/Steve_Kieu)\
**Post date:** [December 18, 2014, 5:46am UTC](https://forum.ansible.com/t/template-source-file-not-getting-from-closest-role/17095/1 "2014-12-18T05:46:38Z")

</div>

Hi All,

I have role A and then B (dependent on A).

I have sudoers.j2 in the templates folder for each role with different content.

When a host with role B applied ansible run the task on role A and apply the source file which is not the one in templates folder of role B. Is it expected behaviour?

Thanks,

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [January 4, 2015, 3:31pm UTC](https://forum.ansible.com/t/template-source-file-not-getting-from-closest-role/17095/2 "2015-01-04T15:31:19Z")

</div>

What is the role dependency in your case?  
Depending on how your roles are written+called this can be expected (i.e. the file gets templated by role B and then overwritten by A).  
Share your code if you need more help.

---

<div class="post-metadata">

**Author:** ![Steve\_Kieu](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Steve\_Kieu](https://forum.ansible.com/u/Steve_Kieu)\
**Post date:** [January 4, 2015, 11:12pm UTC](https://forum.ansible.com/t/template-source-file-not-getting-from-closest-role/17095/3 "2015-01-04T23:12:16Z")

</div>

Hi,

Thanks . As I wrote, B is dependent (a child) of role A.

In B task there is no template module called with source is sudoer2.j2. A has one like this so when a host has role B - the first role A is called and that template module is called. But it does not use the source sudoer2.j2 located in role B templates folder. it uses the source file from the templates folder of role A.

At the moment I have to put the template module in role B tasks and that is called twice - role A with role A templates source and then role B with role B template source. The end result is OK but because each repeated run - role A sees that the file has changed (because the source of B templates is different from A) then it templates it again, and then B does the same.

So end result is also OK but the template module always run!

The expected behaviour are:

- We do not need to call the template task on role B.
- If in role B templates folder has the source file, then when the template task in role A is called it should use the source file from the template folder of role B because it is closer role to the target host.

cheers
