# ansible looking for templates in previous role

**URL:** <https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548>\
**Category:** Ansible Project\
**Created:** [October 26, 2023, 11:22am UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548 "2023-10-26T11:22:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [October 26, 2023, 11:22am UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/1 "2023-10-26T11:22:21Z")

</div>

Good morning. I have two roles in a multi-role playbook, for yum, then chrony. The yum module works fine, but the chrony playbook fails on copying a template. The odd thing is, the error I get indicates ansible is looking in the yum module for chrony’s template. here is the specific error message;

Could not find or access chrony.conf.j2

Searched in:  
/work/roles/yum/templates/chrony.conf.j2  
/work/roles/yum/chrony.conf.j2  
/work/roles/yum/tasks/chrony.conf.j2  
/work/templates/etc.chrony.conf.j2

Why is it searching in the yum role for a chrony template? The template is in /work/roles/chrony/templates/chrony.conf.j2.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [October 26, 2023, 11:45am UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/2 "2023-10-26T11:45:20Z")

</div>

Please provide the code that is executing the roles.

Walter

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 26, 2023, 1:32pm UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/3 "2023-10-26T13:32:16Z")

</div>

Hi Kathy,

Files, templates, plugins, etc. that live in various local roles aren’t available to your playbook tasks until those roles are accessed, for example through the roles: playbook keyword or import\_role or include\_role.

From your description, it appears that you’ve accessed your yum role but not your chrony role at the point you tried to use your etc.chrony.conf.j2 template.

---

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [October 26, 2023, 7:31pm UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/4 "2023-10-26T19:31:06Z")

</div>

Walter - Unfortunately I can’t provide the code as this is on a client’s off-line network. Todd, I’ll look again at when I use the chrony tasks.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [October 26, 2023, 7:34pm UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/5 "2023-10-26T19:34:46Z")

</div>

You would only call the chrony role. Something like this.

- include\_role:  
name: yum\_role.yaml

- include\_role:  
name: chrony\_role.yaml

The role would use the template module which should find the template in the chrony role’s templates folder.

Walter

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 27, 2023, 3:15pm UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/6 "2023-10-27T15:15:14Z")

</div>

You can just post a simple reproducer, from what you posted I can only  
vaguely guess that you are using the 2nd role tasks as tasks and not  
as a role.

---

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [October 30, 2023, 2:48pm UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/7 "2023-10-30T14:48:05Z")

</div>

What I did today was to remove mitogen and run it with “normal” ssh and it did not have that problem. That makes it a mitogen problem I think. I’ll find a bug report with them. I should have thought of this earlier. Thanks for all the help.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 30, 2023, 3:17pm UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/8 "2023-10-30T15:17:16Z")

</div>

Post a simple reproducer here before you file the issue. Included or  
depending role might be causing the problem. This might be an issue  
with Ansible. See [https://stackoverflow.com/a/76994183/6482561](https://stackoverflow.com/a/76994183/6482561)

---

<div class="post-metadata">

**Author:** ![Terry\_Bowling](https://avatars.discourse-cdn.com/v4/letter/t/48db29/32.png) [@Terry\_Bowling](https://forum.ansible.com/u/Terry_Bowling)\
**Post date:** [October 30, 2023, 4:04pm UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/9 "2023-10-30T16:04:08Z")

</div>

Hello Kathy,  
I cannot answer the template question, but for configuring Chrony, have you considered using the RHEL System Roles.timesync role (or it’s upstream project linux-system-roles)?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 30, 2023, 4:33pm UTC](https://forum.ansible.com/t/ansible-looking-for-templates-in-previous-role/38548/10 "2023-10-30T16:33:47Z")

</div>

This is how resolution should work in Ansible  
[https://docs.ansible.com/ansible/latest/playbook\_guide/playbook\_pathing.html#resolving-local-relative-paths](https://docs.ansible.com/ansible/latest/playbook_guide/playbook_pathing.html#resolving-local-relative-paths),  
if this is not what you are seeing, then file a bug with a simple  
reproducer w/o mitogen. We do not support mitogen patch as it does  
alter some base functionality in backwards incompatible ways, any  
issues with mitogen can be address at it's own issue site.
