Hi, I am very new to Ansible and I have a question regarding the template module.
I am receiving an error running a playbook where ansible cannot find or access the j2 file.
If I transfer the file manually into /tmp/kitchen/ where it says it is looking, then it runs fine. I am using Test Kitchen with kitchen-ansible, Vagrant and Inspec on Windows. Is the template file not supposed to be sent to the host with kitchen? Maybe this is a Test Kitchen issue of not generating the files on the target?
Thank you for any guidance.
Hard to guess what’s going on here without seeing your playbook and template file, but my guess would be the template (.j2) file isn’t in one of the places that ansible expects to find it.
If your template is in a role (best place for it) then there are some rules about where ansible will look for templates (and other files) described here:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html#using-roles
I can’t speak for ‘kitchen’ as I haven’t used for it, but the template
module should copy (templated) files to the destination that is specified - but if it can’t find the template then it wont of course.
Hope this helps,
Jon
Thanks, my directory structure is as follows:
/
.kitchen.yml
roles/common/
–/tasks/playbook.yml
–/templates/create_motd.j2
test/
`
//.kitchen.yml
Hmm, as I say I don’t know what kitchen expects, however it strikes me as unusual to have your playbook stored in the tasks folder of your role. Generally playbooks list one or more roles that should be applied to the hosts in the current play, so it seems odd to have the playbook stored in with the role.
Can you try just using ‘bare’ ansible without it being wrapped in kitchen?
Might be worth running ansible-playbook with -vvvvv to get debugging information including the paths where it is looking for things.
Hope this helps,
Jon