This is hard for me to follow where you have defined these variables, how
about sharing everything in a gist?




On Wed, Apr 30, 2014 at 3:02 PM, RobL <[email protected]> wrote:

> 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<https://groups.google.com/d/msgid/ansible-project/1ee39758-80a7-48fe-a2ca-059b11a6c000%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CA%2BnsWgwrCwgvxFFo8foSZW%3DE7r%3DER_gGzDqChhCGfoiHKkCisQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to