Created
May 2, 2014 16:15
-
-
Save anonymous/1ca1385f46a688ed2561 to your computer and use it in GitHub Desktop.
Ansible issue: Jinja2 converting double quotes to single quotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible-playbook -e "@test/values.json" -vvvv ./test.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"keepDoubleQuotes": [ {"name": "value"} ], | |
"loseDoubleQuotes": [{'name2': 'value2nestedValue'}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: dbg | |
debug: var=keepDoubleQuotes | |
- name: dbg2 | |
debug: var=loseDoubleQuotes | |
- name: template | |
template: src="test.j2" | |
dest="/var/tmp/output.json" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"keepDoubleQuotes": {{ keepDoubleQuotes}}, | |
"loseDoubleQuotes": {{ loseDoubleQuotes}} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
keepDoubleQuotes: '[ | |
{"name": "value"} | |
]', | |
"nestedVar": "nestedValue", | |
loseDoubleQuotes: '[ | |
{ "name2": "value2{{ nestedVar }}" } | |
]', | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# 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