Can I run an ansible jinja2-template as script directly on the client?
(Instead of copying the template first as file and then giving it the executable rights and then execute it)
Can I run an ansible jinja2-template as script directly on the client?
(Instead of copying the template first as file and then giving it the executable rights and then execute it)
I know it's been an old topic but I'm just putting my thoughts in case anyone googled here. You cannot have template variables in the script, but you can pass template variables when calling the script module. So I'm suggesting you refactor your script and parameterize everything you intended to be template variables. Something like:
- name: call some script
script: "some_script.sh {{ some_variable }}"
It's not every bit you asked for, but you also don't need two steps to get the job done.
The modern answer is Yes:
- name: Execute any_your_script.sh.j2
shell: "{{ lookup('template', 'any_your_script.sh.j2') }}"
register: any_your_script_result