[openstack-dev] [kolla] potential Ansible template issue you may meet

Jeffrey Zhang zhang.lei.fly at gmail.com
Tue Sep 13 02:15:44 UTC 2016


When using ansible template module, you may see the trailing newline
is stripped by blocks, like

# template.j2
a = {% if true %}1{% endfor %}
b = 2

the render will be like

a=1b=2

The newline character after `a=1` is stripped.

The root cause comes from jinja2's trim_blocks feature. Ansible
enabled this feature. If you want to disable it, just add `#jinja2:
trim_blocks: False` to the j2 template file. This is a feature in
Ansible, and I do not think they will fix/change this. But we need
take care of this when using the template module.

More info please check[0][1]

[0] https://github.com/ansible/ansible/issues/16344
[1] http://jinja.pocoo.org/docs/dev/api/#jinja2.Environment

-- 
Regards,
Jeffrey Zhang
Blog: http://xcodest.me



More information about the OpenStack-dev mailing list