title: ansible, jinja template with loops, losing newlines
body: <p>Trying to build a JSON file from a template.  It works ok as such, but for some reason newlines within loop constructs go missing, which I find rather irksome; the file "works" (is machine readable just fine), but for human consumption it's pretty ill-suited. </p>
  
  <p>Here's my template:</p>
  
  <pre><code>{
          "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 %}
          ]
  }
  </code></pre>
  
  <p>Here's some sample data:</p>
  
  <pre><code>  - andrej:
        name: "andrej"
        hash: "$2b$10$8EF3H.../Wj0RchEqU6"
        cns:
          h:
            - "andrej_linux_h_201808171440"
            - "andrej_linuxvm_h_201809131031"
            - "andrej_mac_h_201808171441"
            - "andrej_phone_h_201808171441"
          w:
            - "andrej_linux_w_201808171439"
            - "andrej_linuxvm_w_201809131031"
            - "andrej_mac_w_201808171441"
            - "andrej_phone_w_201808171441"
        keys:
          - name: "andrej"
            public: "kbjrvtni"
          - name: "andrej2"
            public: "ijrltifu"
          - name: "andrej3"
            public: "rbcvncbt"
        comment: "systems"
  </code></pre>
  
  <p>This is my desired outcome (running against server "w"): </p>
  
  <pre><code>{
      "Users": 
      [
              {
                      "Name" : "andrej",
                      "Hash" : "$2b$10$8EF3H.../Wj0RchEqU6",
                      "Cns"  : [ 
                              "andrej_linux_w_201808171439",
                              "andrej_linuxvm_w_201809131031",
                              "andrej_mac_w_201808171441",
                              "andrej_phone_w_201808171441"
                      ],
                      "key_ids" : [ 
                              "kbjrvtni",
                              "ijrltifu",
                              "rbcvncbt" 
                      ],
                      "comment" : "systems guy"
              }
       ]
  }
  </code></pre>
  
  <p>This is what I get:</p>
  
  <pre><code>{
      "Users": 
      [
              {
                      "Name" : "andrej",
                      "Hash" : "$2b$10$8EF3H.../Wj0RchEqU6",
                      "Cns"  : [ 
                              "andrej_linux_w_201808171439",                                "andrej_linuxvm_w_201809131031",                                "andrej_mac_w_201808171441",                                "andrej_phone_w_201808171441"                        ],
                      "key_ids" : [ 
                              "kbjrvtni",                                "ijrltifu",                                "rbcvncbt"                         ],
                      "comment" : "systems guy"
              }
       ]
  }
  </code></pre>
  
  <p>I have experimented with <code>#Jinja2: trim_blocks</code> and <code>#Jinja2: keep_newline</code>, neither of which showed the desired result. Well, trim_blocks <em>kind</em> of did, but it also gave me a bunch of empty lines where the jinja conditionals were  ... unsatisfactory.</p>
  
  <p>Any hints on how to resolve this?  As I said, it works, but it <strong>irks</strong> me immensely that I can't get human readable, nice output.</p>