While working on the openvpn script, I noticed the produced config file had a lot of extra blank lines, so I tried to clean up the Jinja template. It turns out whitespace handling in Jinja2 is not trivial, and a template that may produce a satisfactory file format in some input data cases, produces a broken format (with missing newlines) in other cases, (usually if a if-statement adds a preceding and trailing newline, the next statement can not add it, and if the preceding if-statement then gets switched off, the next statement ends up adding text without a newline).
So to produce nicely looking files with manual whitespace control, a lot of care is required. To help me work on and test the template, I used an online template live parser: http://jinja.quantprogramming.com/
I haven't tried trim_blocks or lstrip_blocks, it seems having manual control is better.
I'd like to keep this task as the parent task for such template cleanup.