Jinja Whitespace control

3,915 views
Skip to first unread message

Michael Peters

unread,
May 6, 2014, 3:29:52 PM5/6/14
to ansible...@googlegroups.com
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) for this.
I get a "tag name expected" error from the template module.

Am I doing something wrong or is this not allowed?

Brian Coca

unread,
May 6, 2014, 5:59:57 PM5/6/14
to ansible...@googlegroups.com
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.​ 

Michael Peters

unread,
May 7, 2014, 10:35:05 AM5/7/14
to ansible...@googlegroups.com
Thanks, I put this at the top of my template and everything worked perfectly.

#jinja2:trim_blocks: False
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CADn%2BHsyyBhPG6XHBB_%2BwJ7DM8WrK6GipfatqUrnVanQFudYWww%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages