# Could not find or access template file

**URL:** <https://forum.ansible.com/t/could-not-find-or-access-template-file/31632>\
**Category:** Ansible Project\
**Created:** [November 11, 2019, 10:48am UTC](https://forum.ansible.com/t/could-not-find-or-access-template-file/31632 "2019-11-11T10:48:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![morten\_hoffmann](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@morten\_hoffmann](https://forum.ansible.com/u/morten_hoffmann)\
**Post date:** [November 11, 2019, 10:48am UTC](https://forum.ansible.com/t/could-not-find-or-access-template-file/31632/1 "2019-11-11T10:48:39Z")

</div>

hi

I’m trying to setup a linux service on remote host

I have my file in template folder

.  
├── group\_vars  
│ ├── artefacts\_conf.yml  
│ ├── jdk\_wl\_conf.yml  
│ ├── configuration\_conf.yml  
├── hosts

└── templates  
├── nodemanager\_service.j2

my roles are using

- name: Copy nodemanager systemd script  
template:  
src: “{{nodemanager\_service\_template}}”  
dest: /lib/systemd/system/nodemanager.service  
mode: 0664  
become: yes

however playbook fails with:

Could not find or access 'nodemanager\_service.j2

any advise?

---

<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:** [November 11, 2019, 11:12am UTC](https://forum.ansible.com/t/could-not-find-or-access-template-file/31632/2 "2019-11-11T11:12:12Z")

</div>

(In the case "Could not find 'nodemanager\_service.j2')

Quoting from "The magic of ‘local’ paths"  
[https://docs.ansible.com/ansible/latest/user\_guide/playbook\_pathing.html#the-magic-of-local-paths](https://docs.ansible.com/ansible/latest/user_guide/playbook_pathing.html#the-magic-of-local-paths)

&nbsp;&nbsp;"The paths will be searched from most specific to most general (i.e role  
&nbsp;&nbsp;before play). ...  
&nbsp;&nbsp;role search path is rolename/{files|vars|templates}/, rolename/tasks/.  
&nbsp;&nbsp;play search path is playdir/{files|vars|templates}/, playdir/."

It's possible to use "Special variables" in a path. For example  
"playbook\_dir", or "role\_path". See  
[https://docs.ansible.com/ansible/latest/reference\_appendices/special\_variables.html](https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html)

Or, link the "template" directory into any of the paths being searched.

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 11, 2019, 11:12am UTC](https://forum.ansible.com/t/could-not-find-or-access-template-file/31632/3 "2019-11-11T11:12:46Z")

</div>

> hi
> 
> I'm trying to setup a linux service on remote host
> 
> I have my file in template folder  
> .  
> ├── group\_vars  
> │ ├── artefacts\_conf.yml  
> │ ├── jdk\_wl\_conf.yml  
> │ ├── configuration\_conf.yml  
> ├── hosts  
> └── templates  
> ├── nodemanager\_service.j2
> 
> my roles are using  
> - name: Copy nodemanager systemd script  
> template:  
> src: "{{nodemanager\_service\_template}}"  
> dest: /lib/systemd/system/nodemanager.service  
> mode: 0664  
> become: yes
> 
> however playbook fails with:
> 
> Could not find or access 'nodemanager\_service.j2
> 
> any advise?

Hello Marten,

try to run the playbook with -vv. This should display the locations where Ansible looks for the template file.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![morten\_hoffmann](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@morten\_hoffmann](https://forum.ansible.com/u/morten_hoffmann)\
**Post date:** [November 11, 2019, 7:21pm UTC](https://forum.ansible.com/t/could-not-find-or-access-template-file/31632/4 "2019-11-11T19:21:53Z")

</div>

hi

I used full path in my vars file. that solve it

{{template\_dir}}/{{template\_file}}

---

<div class="post-metadata">

**Author:** ![sdoran](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sdoran](https://forum.ansible.com/u/sdoran)\
**Post date:** [November 12, 2019, 4:00pm UTC](https://forum.ansible.com/t/could-not-find-or-access-template-file/31632/5 "2019-11-12T16:00:10Z")

</div>

The templates directory is only searched within a role. A directory named templates next to a playbook is not searched. You will need to reference the path to the template file. I usually use playbook\_dir variable, but you could also just use templates/. See the [variables documentation](https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#special-variables) for more details.

Either of these should work:

src: “{{ playbook\_dir }}/templates/{{ nodemanager\_service\_template }}”

or

src: templates/{{ nodemanager\_service\_template }}

---

<div class="post-metadata">

**Author:** ![Nivedita](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@Nivedita](https://forum.ansible.com/u/Nivedita)\
**Post date:** [December 11, 2019, 8:10am UTC](https://forum.ansible.com/t/could-not-find-or-access-template-file/31632/6 "2019-12-11T08:10:05Z")

</div>

Hi Morten,

Please try :

- name: Copy nodemanager systemd script  
template:  
src: nodemanager\_service\_template.j2L  
dest: /lib/systemd/system/nodemanager.service  
mode: 0664  
become: yes

Hope this will work!

Regards,  
Nivedita
