# Jinja Whitespace control

**URL:** <https://forum.ansible.com/t/jinja-whitespace-control/15174>\
**Category:** Ansible Project\
**Created:** [May 6, 2014, 7:29pm UTC](https://forum.ansible.com/t/jinja-whitespace-control/15174 "2014-05-06T19:29:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [May 6, 2014, 7:29pm UTC](https://forum.ansible.com/t/jinja-whitespace-control/15174/1 "2014-05-06T19:29:52Z")

</div>

I'm using a single line jinja block in a templated configuration file.  
Jinja is stripping the newline character at the end of this block  
causing the next line to be collapsed thus breaking the configuration  
file.

I assume I could set some global jinja options in the ansible.config  
file, but I want to control the whitespace on a per-usage basis. But  
Jinja (or Ansible, not sure which) is breaking when I try to use the  
+/- control characters that Jinja documents  
([http://jinja.pocoo.org/docs/templates/#whitespace-control](http://jinja.pocoo.org/docs/templates/#whitespace-control)) for this.  
I get a "tag name expected" error from the template module.

Am I doing something wrong or is this not allowed?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [May 6, 2014, 9:59pm UTC](https://forum.ansible.com/t/jinja-whitespace-control/15174/2 "2014-05-06T21:59:57Z")

</div>

ansible loads jinja2 with trim\_blocks = true, you can use a per template header to override this, you can see an example in the template docs.​

[https://docs.ansible.com/template\_module.html](https://docs.ansible.com/template_module.html)

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [May 7, 2014, 2:35pm UTC](https://forum.ansible.com/t/jinja-whitespace-control/15174/3 "2014-05-07T14:35:05Z")

</div>

Thanks, I put this at the top of my template and everything worked perfectly.

#jinja2:trim\_blocks: False
