# 2 extra spaces in front of on some rendered lines in for loops

**URL:** <https://forum.ansible.com/t/2-extra-spaces-in-front-of-on-some-rendered-lines-in-for-loops/24012>\
**Category:** Ansible Project\
**Created:** [March 20, 2017, 12:44am UTC](https://forum.ansible.com/t/2-extra-spaces-in-front-of-on-some-rendered-lines-in-for-loops/24012 "2017-03-20T00:44:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry1](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@jerry1](https://forum.ansible.com/u/jerry1)\
**Post date:** [March 20, 2017, 12:44am UTC](https://forum.ansible.com/t/2-extra-spaces-in-front-of-on-some-rendered-lines-in-for-loops/24012/1 "2017-03-20T00:44:54Z")

</div>

Hi,

I am generating config files and I want them to be indented just so. I started with a jinja2 template that rendered correctly when called from a simple python program. When I call it from ansible, I will get 2 extra spaces on all but the first line of the loop. Generating things like yaml and python has been a real pain. I have taken to putting a comment line as the first line of a for block to fix this…

Here is a really simple example of a yaml generator:  
_playbook call:_

- name: generate bgp vars file, put in includes directory

local\_action: template src={{ role\_dir }}/templates/bgp\_vars.j2 dest={{ incvar\_dir }}/bgp\_vars.yaml

run\_once: true

_section of template:_

dc\_route\_reflectors:

{% for dc in SH\_dcs %}

# dc is “{{ dc }}”

{{ dc }}:

{% for host in groups[bgpgroupname] if dc == hostvars[host].MYDC %}

- “{{ hostvars[host].MAIN\_MYADDR }}”

{% endfor %}

{% endfor %}

_rendered output:_

dc\_route\_reflectors:

# dc is “pnp”

pnp:

- “10.100.16.3”

- “10.100.32.3”

# dc is “sgs”

sgs:

- “10.8.0.3”

- “10.8.16.3”

# dc is “cst”

cst:

- “10.4.0.3”

- “10.4.16.3”

# dc is “dse”

dse:

- “10.200.0.3”

- “10.200.16.3”

Notice how the pnp comment is not indented as it is shown in the template, but sgs,cst and dse are indented by 2 spaces. All of the array lines of ip addresses are also indented. I have tried various versions of adding “-” to the “%” things as Jinja2 describes, but none have given consistent correct results.

Others must have seen this before. I’m running 2.2.1.0 on centos7.
