template source file not getting from closest role

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,

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.

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