I can't get this jinja2 template to work. Can somebody help me out? I've tried the Jinja2 Live templater but I don't get the result I need.
Let's say I have the following group_vars/all.yml file:
disk_iops: 500
disk_space:
"C:": 10
"D:": 10
"E:": 10
core_count: 8
And the following template: name.json.j2
{
"DiskIO": "{{ disk_iops }}",
{% if disk_space is defined and disk_space -%}
"DiskSpace": {
{%- set comma = joiner(",") -%}
{%- for key, value in disk_space.items() -%}
{{ comma() }}
"{{ key }}": "{{ value }}"
{%- endfor %}
},
{% endif -%}
"CoreCount": "{{ core_count }}"
}
I get the following result:
{
"DiskIO": "500",
"DiskSpace": {
"C:": "70",
"D:": "100",
"E:": "10" },
"CoreCount": "4"
}
But I would like the }
to be on a new line