Thank you! That fixed the problem.
On Friday, May 2, 2014 12:15:38 PM UTC-7, Michael DeHaan wrote:
>
> Just as a quick PSA, you can actually use YAML for parameters passed in to
> "-e @test/values" if you like.
>
> In the above example, nestedVar is expressed as a string, but that string
> actually contains no quotes, so that's why you are not seeing quotes there.
>
> The easiest suggestion here if you are trying to write a datastructure as
> json, is to have a template that is exactly this:
>
> {{ datastructure | to_json }}
>
> And it will do the right thing and use the kind of quoting that JSON
> entails.
>
> This also has the added benefit of keeping everything in nice pure
> datastructures and not having to write something in a format for a
> particular datastructure.
>
> By no means should you have to worry about regex replacements to solve
> this, that would be horribly painful :)
>
>
>
>
> On Fri, May 2, 2014 at 12:17 PM, RobL <[email protected] <javascript:>>wrote:
>
>> https://gist.github.com/anonymous/1ca1385f46a688ed2561
>>
>> The output I see is:
>> "loseDoubleQuotes": [{'name2': 'value2nestedValue'}]
>>
>> What I expect to see is:
>> "loseDoubleQuotes": [{"name2": "value2nestedValue"}]
>>
>> Thanks for looking.
>>
>> Rob
>>
>> On Thursday, May 1, 2014 2:25:41 PM UTC-7, Michael DeHaan wrote:
>>
>>> 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] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/3f39bd58-3073-4c70-b55c-790c3d0b63d6%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/3f39bd58-3073-4c70-b55c-790c3d0b63d6%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/a9bcb5a8-a43e-4262-abaf-8f775d5e5906%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.