From 3efc7142a6ca72bfb40e63c49ed64e2e04837c51 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 18 Nov 2014 09:40:57 -0600 Subject: 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. LP: #1355343 --- ChangeLog | 2 ++ cloudinit/templater.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0cac0f04..1debc923 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ - expose uses_systemd as a distro function (fix rhel7) - fix broken 'output' config (LP: #1387340) - 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: - open 0.7.6 - Enable vendordata on CloudSigma datasource (LP: #1303986) diff --git a/cloudinit/templater.py b/cloudinit/templater.py index 02f6261d..4cd3f13d 100644 --- a/cloudinit/templater.py +++ b/cloudinit/templater.py @@ -89,9 +89,11 @@ def detect_template(text): return CTemplate(content, searchList=[params]).respond() 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, undefined=jinja2.StrictUndefined, - trim_blocks=True).render(**params) + trim_blocks=True).render(**params) + add if text.find("\n") != -1: ident, rest = text.split("\n", 1) -- cgit v1.2.3