Tag Archives: salt

jinja create file from template without empty lines


Creation of file from pillar simple list with Jinja template will be create empty line, in top or bottom of file, dependence for template syntax.
You can not create file without empty lines.

from jinja2 import Template

d = {'testlist':['item1','item2','item3']}

tmpl = '''{%- for item in testlist %}
   {{ item }}
{%- endfor %}'''

t = Template(tmpl)
print( t.render( d ) )

Continue reading