summaryrefslogtreecommitdiff
path: root/cloudinit/templater.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-11-18 09:40:57 -0600
committerScott Moser <smoser@ubuntu.com>2014-11-18 09:40:57 -0600
commit3efc7142a6ca72bfb40e63c49ed64e2e04837c51 (patch)
treee102e25b4ac7e8c3551b5113214b12c44cd9ded6 /cloudinit/templater.py
parent9eed0fef5030e2e66f4bc1e549783638087786f4 (diff)
downloadcloud-init-git-3efc7142a6ca72bfb40e63c49ed64e2e04837c51.tar.gz
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
Diffstat (limited to 'cloudinit/templater.py')
-rw-r--r--cloudinit/templater.py4
1 files changed, 3 insertions, 1 deletions
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)