Could not find or access template file

1,564 views
Skip to first unread message

morten hoffmann

unread,
Nov 11, 2019, 5:48:39 AM11/11/19
to Ansible Project
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
 - nameCopy nodemanager systemd script
   template:
    src"{{nodemanager_service_template}}"
    dest/lib/systemd/system/nodemanager.service
    mode0664
   becomeyes


however playbook fails with:

Could not find or access 'nodemanager_service.j2

any advise?

Vladimir Botka

unread,
Nov 11, 2019, 6:12:27 AM11/11/19
to morten hoffmann, ansible...@googlegroups.com
On Mon, 11 Nov 2019 02:48:39 -0800 (PST)
morten hoffmann <mhoff...@gmail.com> wrote:

> .
> ├── 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
>
> Could not find or access 'nodemanager_service.j2'

(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

"The paths will be searched from most specific to most general (i.e role
before play). ...
role search path is rolename/{files|vars|templates}/, rolename/tasks/.
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

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

Cheers,

-vlado

Stefan Hornburg (Racke)

unread,
Nov 11, 2019, 6:13:11 AM11/11/19
to ansible...@googlegroups.com
Hello Marten,

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

Regards
Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/37ed9cea-55ea-4acd-8352-bedc2f1a41c9%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/37ed9cea-55ea-4acd-8352-bedc2f1a41c9%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

morten hoffmann

unread,
Nov 11, 2019, 2:21:53 PM11/11/19
to Ansible Project
hi

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

{{template_dir}}/{{template_file}}

Sam Doran

unread,
Nov 12, 2019, 11:00:27 AM11/12/19
to ansible...@googlegroups.com
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 for more details.


Either of these should work:

src: "{{ playbook_dir }}/templates/{{ nodemanager_service_template }}"

or

src: templates/{{ nodemanager_service_template }}

---

Sam

mili singh

unread,
Dec 11, 2019, 3:10:05 AM12/11/19
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages