retain trailing newline from template files when using jinja2

sources.list was where this showed itself, but all rendered files
would have their newline stripped.
This commit is contained in:
Scott Moser 2014-11-18 09:40:57 -06:00
parent cf33f2bbc0
commit bc8b165643
2 changed files with 5 additions and 1 deletions

View File

@ -4,6 +4,8 @@
- expose uses_systemd as a distro function (fix rhel7) - expose uses_systemd as a distro function (fix rhel7)
- fix broken 'output' config (LP: #1387340) - fix broken 'output' config (LP: #1387340)
- begin adding cloud config module docs to config modules (LP: #1383510) - begin adding cloud config module docs to config modules (LP: #1383510)
- retain trailing eol from template files (sources.list) when
rendered with jinja (LP: #1355343)
0.7.6: 0.7.6:
- open 0.7.6 - open 0.7.6
- Enable vendordata on CloudSigma datasource (LP: #1303986) - Enable vendordata on CloudSigma datasource (LP: #1303986)

View File

@ -89,9 +89,11 @@ def detect_template(text):
return CTemplate(content, searchList=[params]).respond() return CTemplate(content, searchList=[params]).respond()
def jinja_render(content, params): def jinja_render(content, params):
# keep_trailing_newline is in jinja2 2.7+, not 2.6
add = "\n" if content.endswith("\n") else ""
return JTemplate(content, return JTemplate(content,
undefined=jinja2.StrictUndefined, undefined=jinja2.StrictUndefined,
trim_blocks=True).render(**params) trim_blocks=True).render(**params) + add
if text.find("\n") != -1: if text.find("\n") != -1:
ident, rest = text.split("\n", 1) ident, rest = text.split("\n", 1)