# Ansible Jinja indentation bug ?

**URL:** <https://forum.ansible.com/t/ansible-jinja-indentation-bug/18637>\
**Category:** Ansible Project\
**Created:** [June 29, 2015, 6:46pm UTC](https://forum.ansible.com/t/ansible-jinja-indentation-bug/18637 "2015-06-29T18:46:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [June 29, 2015, 6:46pm UTC](https://forum.ansible.com/t/ansible-jinja-indentation-bug/18637/1 "2015-06-29T18:46:14Z")

</div>

Hi,

I have the bellow vars to populate a template , it works almost fine but the final file result you can see there is some indentation problem :

# vars :

datadog\_http\_checks:

- name : mycheck  
url : [http://localhost:9090/hc/](http://localhost:9090/hc/)  
threshold : 5

window : 5  
timeout : 1

# template:

init\_config:

instances:  
{% for http in datadog\_http\_checks %}

- name: {{ http.name }}  
{% if http.url is defined -%}  
url: {{ http.url }}  
{% endif -%}  
{% if http.threshold is defined -%}  
threshold: {{ http.threshold }}  
{% endif %}  
{% if http.window is defined -%}  
window: {{ http.window }}  
{% endif %}  
{% if http.timeout is defined -%}  
timeout: {{ http.timeout }}  
{% endif %}  
{% if http.include\_content is defined -%}  
include\_content: {{ http.include\_content }}  
{% endif %}  
notify:
- pagerduty

{% endfor %}

# result :

instances:

- name: mycheck  
url: [http://localhost:9090/hc/](http://localhost:9090/hc/)  
threshold: 5  
window: 5  
timeout: 1  
notify:
- pagerduty

Is this a bug or am I doing something wrong ?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 29, 2015, 6:55pm UTC](https://forum.ansible.com/t/ansible-jinja-indentation-bug/18637/2 "2015-06-29T18:55:03Z")

</div>

The problem from what I can remember is that ansible does not specify lstrip\_blocks, and as such, it can cause indentation issues.

The approach I take, it to left justify all jinja2 control blocks. So all {% %} lines would have no indentation, only the lines inside would be indented.

such as:

{% for http in datadog\_http\_checks %}

- name: {{ [http.name](http://http.name/) }}  
{% if http.url is defined -%}  
url: {{ http.url }}  
{% endif -%}

…  
{% endfor %}

---

<div class="post-metadata">

**Author:** ![Ioan\_surname](https://avatars.discourse-cdn.com/v4/letter/i/439d5e/32.png) [@Ioan\_surname](https://forum.ansible.com/u/Ioan_surname)\
**Post date:** [July 15, 2016, 1:03pm UTC](https://forum.ansible.com/t/ansible-jinja-indentation-bug/18637/3 "2016-07-15T13:03:37Z")

</div>

Joined this group just to give you a shout out Matt, all became clear as soon as I read your reply.  
Thanks man, you rock,  
Ioan
