[Solved] ansible, jinja template with loops, losing newlines [duplicate]


And this little change actually made the problem go away in the end.

#jinja2: trim_blocks:False
{
        "Users": 
        [
{% for username,user in _vpn_user_accounts.items() %}
              {
              "Name" : "{{ user.name }}",
              "Hash" : "{{ user.hash }}",
              "Cns" : [
{%- for cn in user.cns.get(server_name, []) %}
                      "{{ cn }}"{% if not loop.last -%},{% endif %}
{%- endfor %}
              ],
              "key_ids" : [
{%- for key in user.get( 'keys' , []) %}
{% if key.public is defined %}
                      "{{ key.public }}"{% if not loop.last %},{% endif %}
{% endif %}
{%- endfor %}
              ],
              "comment" : "{{ user.get( 'comment', '' ) }}"
              } {% if not loop.last %},{% endif %}
{% endfor %}
        ]
}

1

solved ansible, jinja template with loops, losing newlines [duplicate]