ansible looking for templates in previous role

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.

Please provide the code that is executing the roles.

Walter

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.

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.

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

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.

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.

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

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)?

This is how resolution should work in Ansible
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.