# Why role cannot find template

**URL:** <https://forum.ansible.com/t/why-role-cannot-find-template/40379>\
**Category:** Get Help\
**Tags:** template, role\
**Created:** [February 19, 2025, 8:30pm UTC](https://forum.ansible.com/t/why-role-cannot-find-template/40379 "2025-02-19T20:30:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwagnergit](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rwagnergit/32/7219_2.png) [@rwagnergit](https://forum.ansible.com/u/rwagnergit)\
**Post date:** [February 19, 2025, 8:30pm UTC](https://forum.ansible.com/t/why-role-cannot-find-template/40379/1 "2025-02-19T20:30:50Z")

</div>

Why would a role be able to find a template on one control machine but not another (both control machines are running out of the same git repo, so the playbooks/roles/templates/ansible.cfg are identical)?

Directory structure is simple:

```auto
playbook_dir/roles/role_name/templates/template.j2

```

If I invoke the playbook on one control machine, it runs as expected; it includes the role, the role finds the template, and everything is happy. But on another control machine, it dies with:

```auto
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option
fatal: [blah.blah.com]: FAILED! => {"changed": false, "msg": "Could not find or access '/home/blah/t/client/../templates/client_sqlnet_no_ldap.ora.j2' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}

```

The search path displayed in the error is NOT the path to the role, so the error is correct, but WHY is Ansible failing to look in the documented ([Search paths in Ansible — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/playbook_guide/playbook_pathing.html#the-magic-of-local-paths)) role search path (i.e., templates directory under the role)?

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [February 19, 2025, 9:42pm UTC](https://forum.ansible.com/t/why-role-cannot-find-template/40379/2 "2025-02-19T21:42:11Z")

</div>

if the role path is not in the search path it is probably looking at a different role.

Are you referencing the template from the role itself?

---

<div class="post-metadata">

**Author:** ![rwagnergit](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rwagnergit/32/7219_2.png) [@rwagnergit](https://forum.ansible.com/u/rwagnergit)\
**Post date:** [February 20, 2025, 12:56pm UTC](https://forum.ansible.com/t/why-role-cannot-find-template/40379/3 "2025-02-20T12:56:13Z")

</div>

Hey @bcoca - yes, the template files are under:

```auto
playbook_dir/roles/role_name/templates/

```

and the task is:

```auto
  - name: create sqlnet.ora
    template:
      src: 'client_sqlnet_ldap.ora.j2'
      dest: /sso/sfw/oracle/instantclient/lib/network/admin/sqlnet.ora
      owner: oracle
      group: dba
      mode: '0644'
      force: no

```

At the bottom of the above docs, I see there is a variable named `ansible_search_path` that allegedly shows the search path, and passing -vvvvv will show the search path. But neither appears to show the template search path.

I’ll try to write a simple role and testcase today.

Rob

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [February 20, 2025, 3:03pm UTC](https://forum.ansible.com/t/why-role-cannot-find-template/40379/4 "2025-02-20T15:03:56Z")

</div>

is that task in the role or from outside the role?

---

<div class="post-metadata">

**Author:** ![rwagnergit](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rwagnergit/32/7219_2.png) [@rwagnergit](https://forum.ansible.com/u/rwagnergit)\
**Post date:** [February 20, 2025, 6:02pm UTC](https://forum.ansible.com/t/why-role-cannot-find-template/40379/5 "2025-02-20T18:02:32Z")

</div>

From within the role. It’s a task in `playbook_dir/roles/role_name/tasks/main.yml`

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [February 20, 2025, 7:03pm UTC](https://forum.ansible.com/t/why-role-cannot-find-template/40379/6 "2025-02-20T19:03:34Z")

</div>

and are you loading the role itself or using an `include_tasks` to the file?

Also note that the ‘search path’ shows the main directories searched, you can append ‘vars’, ‘files’ or ‘templates’ depending on the context of the caller.

---

<div class="post-metadata">

**Author:** ![rwagnergit](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rwagnergit/32/7219_2.png) [@rwagnergit](https://forum.ansible.com/u/rwagnergit)\
**Post date:** [February 20, 2025, 8:56pm UTC](https://forum.ansible.com/t/why-role-cannot-find-template/40379/7 "2025-02-20T20:56:44Z")

</div>

This is fixed. Very silly mistake. The template is named:

```auto
client_sqlnet_ldap.ora.j2

```

But I was missing an underscore in the name. In this “highly regulated” environment, they use Delinea connection manager for access, and it renders underscores and spaces identically, so I didn’t see it! Ugh.

So sorry to waste your time, Brian.
