Edit: As suggested by Vladimir Botka here is a minimal example.
I have this template file json.j2
{"foo":"{{ var }}"}
which I would like to render into a variable and insert that variable into another template
- name render it
ansible.builtin.template:
src: another.j2
[...]
vars:
json_from_template: "{{ lookup('template', 'json.j2') }}"
As it seems ansible interprets the json from json.j2 and changes it to
{ 'foo': 'var_value' }
But "because of reasons" I need the json unchanged, no spaces, no single quotes, as specified in the json.j2.
Can I tell ansible to keep the result of json.j2 as a raw string?
I already tried !unsafe, but this
vars:
json_from_template: !unsafe "{{ lookup('template', 'json.j2') }}"
only renders the raw lookup command without any templating at all, and this
vars:
json_from_template: "{{ !unsafe lookup('template', 'json.j2') }}"
does not work at all.