Skip to content

Instantly share code, notes, and snippets.

Created May 2, 2014 16:15
Show Gist options
  • Save anonymous/1ca1385f46a688ed2561 to your computer and use it in GitHub Desktop.
Save anonymous/1ca1385f46a688ed2561 to your computer and use it in GitHub Desktop.
Ansible issue: Jinja2 converting double quotes to single quotes
ansible-playbook -e "@test/values.json" -vvvv ./test.yml
{
"keepDoubleQuotes": [ {"name": "value"} ],
"loseDoubleQuotes": [{'name2': 'value2nestedValue'}]
}
TASK: [test | dbg] ************************************************************
ok: [...] => {
"item": "",
"keepDoubleQuotes": [
{
"name": "value"
}
]
}
TASK: [test | dbg2] ***********************************************************
ok: [...] => {
"item": "",
"loseDoubleQuotes": [
{
"name2": "value2nestedValue"
}
]
}
TASK: [test | template] *******************************************************
<...> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO ...
<...> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1398883576.25-216619941571149 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1398883576.25-216619941571149 && echo $HOME/.ansible/tmp/ansible-tmp-1398883576.25-216619941571149'
<...> EXEC /bin/sh -c 'rc=0; [ -r "/var/tmp/output.json" ] || rc=2; [ -f "/var/tmp/output.json" ] || rc=1; [ -d "/var/tmp/output.json" ] && echo 3 && exit 0; (/usr/bin/md5sum /var/tmp/output.json 2>/dev/null) || (/sbin/md5sum -q /var/tmp/output.json 2>/dev/null) || (/usr/bin/digest -a md5 /var/tmp/output.json 2>/dev/null) || (/sbin/md5 -q /var/tmp/output.json 2>/dev/null) || (/usr/bin/md5 -n /var/tmp/output.json 2>/dev/null) || (/bin/md5 -q /var/tmp/output.json 2>/dev/null) || (/usr/bin/csum -h MD5 /var/tmp/output.json 2>/dev/null) || (/bin/csum -h MD5 /var/tmp/output.json 2>/dev/null) || (echo "${rc} /var/tmp/output.json")'
<...> PUT /tmp/tmpxv4m9e TO /home/vbce/.ansible/tmp/ansible-tmp-1398883576.25-216619941571149/source
<...> PUT /tmp/tmpaDveH7 TO /home/vbce/.ansible/tmp/ansible-tmp-1398883576.25-216619941571149/copy
<...> EXEC /bin/sh -c '/usr/bin/python /home/vbce/.ansible/tmp/ansible-tmp-1398883576.25-216619941571149/copy; rm -rf /home/vbce/.ansible/tmp/ansible-tmp-1398883576.25-216619941571149/ >/dev/null 2>&1'
changed: [...] => {"changed": true, "dest": "/var/tmp/output.json", "gid": 1501, "group": "voicebox", "item": "", "md5sum": "fc7c06b12fbf99827cda1fd2daab7387", "mode": "0644", "owner": "root", "secontext": "unconfined_u:object_r:user_home_t:s0", "size": 108, "src": "/home/vbce/.ansible/tmp/ansible-tmp-1398883576.25-216619941571149/source", "state": "file", "uid": 1503}
PLAY RECAP ********************************************************************
... : ok=4 changed=1 unreachable=0 failed=0
---
- name: dbg
debug: var=keepDoubleQuotes
- name: dbg2
debug: var=loseDoubleQuotes
- name: template
template: src="test.j2"
dest="/var/tmp/output.json"
{
"keepDoubleQuotes": {{ keepDoubleQuotes}},
"loseDoubleQuotes": {{ loseDoubleQuotes}}
}
{
keepDoubleQuotes: '[
{"name": "value"}
]',
"nestedVar": "nestedValue",
loseDoubleQuotes: '[
{ "name2": "value2{{ nestedVar }}" }
]',
}
---
# Playbook to test how Jinja2 handles quotes in nested variables
- name: test quotes
hosts: all
roles:
- test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment