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?
vbotka
(Vladimir Botka)
November 11, 2019, 11:12am
2
(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
racke
(Stefan Hornburg)
November 11, 2019, 11:12am
3
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
Racke
hi
I used full path in my vars file. that solve it
{{template_dir}}/{{template_file}}
sdoran
November 12, 2019, 4:00pm
5
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 }}