{% if flattened -%}
- name: {{ name }}-image.service
  command: start
  content: |
    [Unit]
    After=docker.service

    [Service]
    Type=oneshot
    ExecStartPre=/usr/bin/curl -s -f -L https://s3.amazonaws.com/devtable-public/importas -o /home/core/importas
    ExecStartPre=/bin/chmod u+x /home/core/importas
    ExecStart=/usr/bin/bash -c '/usr/bin/curl -s -f -L {{ flattened_url(container, tag, username, password) }} | /home/core/importas {{ container }} {{ tag }} | docker load'
{%- endif %}
- name: {{ name }}.service
  command: start
  content: |
    [Unit]
    After=docker.service
    {% if flattened -%}
    After={{ name }}-image.service
    {%- endif %}
    {% for after in after_units -%}
    After={{ after }}
    {%- endfor %}

    [Service]
    Restart={{ restart_policy }}
    TimeoutStartSec=600
    TimeoutStopSec=2000
    {% if username and password and not flattened %}
    ExecStartPre=/usr/bin/docker login -u {{ username }} -p {{ password }} -e unused {{ container|registry }}
    {% endif %}
    ExecStart=/usr/bin/docker run --rm {{ extra_args }} --name {{ name }} {{ container }}:{{ tag }} {{ command }}
    ExecStop=/usr/bin/docker stop {{ name }}
    {% for stop_post in exec_stop_post -%}
    ExecStopPost={{ stop_post }}
    {%- endfor %}

{% if flattened -%}
- name: {{ name }}-image.service
  command: start
  content: |
    [Unit]
    After=docker.service

    [Service]
    Type=oneshot
    ExecStartPre=/usr/bin/curl -s -f -L https://s3.amazonaws.com/devtable-public/importas -o /home/core/importas
    ExecStartPre=/bin/chmod u+x /home/core/importas
    ExecStart=/usr/bin/bash -c '/usr/bin/curl -s -f -L {{ flattened_url(container, tag, username, password) }} | /home/core/importas {{ container }} {{ tag }} | docker load'
{%- endif %}
- name: {{ name }}.service
  command: start
  content: |
    [Unit]
    After=docker.service
    {% if flattened -%}
    After={{ name }}-image.service
    {%- endif %}
    {% for after in after_units -%}
    After={{ after }}
    {% endfor %}

    [Service]
    Restart={{ restart_policy }}
    TimeoutStartSec=600
    TimeoutStopSec=2000
    {% if username and password and not flattened %}
    ExecStartPre=/usr/bin/docker login -u {{ username }} -p {{ password }} -e unused {{ container|registry }}
    {% endif %}
    ExecStart=/usr/bin/docker run --rm {{ extra_args }} --name {{ name }} {{ container }}:{{ tag }} {{ command }}
    ExecStop=/usr/bin/docker stop {{ name }}
    {% for stop_post in exec_stop_post -%}
    ExecStopPost={{ stop_post }}
    {% endfor %}

Fix after_units and exec_stop_post loops
Fix after_units and exec_stop_post loops

Whitespace control was done incorrectly in these two loops, leading to multiple after_units and exec_stop_post to be badly rendered. No line break appeared between each item.