On Friday, 24 November 2017 17.18.26 CET Christian Iuga wrote:
> Hi,
> 
> I'm trying to build custom json file like this : 
> 
> 
> {
>   "client": {
>     "subscriptions": {{ sensu_client_subscriptions | to_nice_json }}
> {% if sensu_autoderegister %}
>     ,"deregister": true,
>     "deregistration": {
>       "handler": "deregister_client"
>     }
> {%endif%}
> {% if sensu_custom_value %}
>    ,{{ sensu_custom_value| to_nice_json  }}
> {%endif%}
>   }
> }
> 
> with variable : 
> sensu_custom_value:
>   disk: 
>     warning: "85"
>     critical: "90"
>   postfix:
>     warning: "10"
>     critical: "20"
> 
> My issue is with {{ sensu_custom_value| to_nice_json  }}
> it's produce unwanted (for me) extra bracket  :

That because the correct representation of sensu_custion_value in json need to 
have those brackets.


>    ,{
>     "disk": {
>         "critical": "90",
>         "warning": "85"
>     },
>     "postfix": {
>         "critical": "20",
>         "warning": "10"
>     }
> }
> 
> 
> i whould like to have, instead : 
>    ,
>     "disk": {
>         "critical": "90",
>         "warning": "85"
>     },
>     "postfix": {
>         "critical": "20",
>         "warning": "10"
>     }
> 
> any idea ? 

You could do something like this, iterate over the keys and print an output.

{% for key in sensu_custom_value %},\n"{{ key }}": {{ sensu_custom_value[key] | 
to_nice_json }}{%endfor%}


-- 
Kai Stian Olstad

-- 
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/2034088.OR6CHYBe67%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply via email to