Hi:
I'm trying to use the template module to create a JSON file.
I'm hitting an issue where some of my double-quotes are converting to
single quotes. Is there a way to ensure that Jinja2 won't do this
conversion? Notice how output.json has double-quotes for the first
variable but single-quotes for the second variable. I've tried various
ways of quoting, both in the template and in values.json.
Sample hitting the issue:
output.json:
{
"keepDoubleQuotes": [ {"name": "value"} ],
"loseDoubleQuotes": [{'name2': 'value2nestedValue'}]
}
test/tasks/main.yml:
---
- name: dbg
debug: var=keepDoubleQuotes
- name: dbg2
debug: var=loseDoubleQuotes
- name: template
template: src="test.j2"
dest="/var/tmp/output.json"
test/templates/test.j2:
{
"keepDoubleQuotes": {{ keepDoubleQuotes}},
"loseDoubleQuotes": {{ loseDoubleQuotes}}
}
test/values.json:
{
keepDoubleQuotes: '[
{"name": "value"}
]',
"nestedVar": "nestedValue",
loseDoubleQuotes: '[
{ "name2": "value2{{ nestedVar }}" }
]',
}
command line:
ansible-playbook -e "@test/values.json" -vvvv ./test.yml
Output:
TASK: [test | dbg]
************************************************************
ok: [...] => {
"item": "",
"keepDoubleQuotes": [
{
"name": "value"
}
]
}
TASK: [test | dbg2]
***********************************************************
ok: [...] => {
"item": "",
"loseDoubleQuotes": [
{
"name2": "value2nestedValue"
}
]
}
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/1ee39758-80a7-48fe-a2ca-059b11a6c000%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.