summaryrefslogtreecommitdiff
path: root/cloudinit/templater.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/templater.py')
-rw-r--r--cloudinit/templater.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/cloudinit/templater.py b/cloudinit/templater.py
index c215bbbb..1e147d4a 100644
--- a/cloudinit/templater.py
+++ b/cloudinit/templater.py
@@ -12,6 +12,7 @@
import collections
import re
+import sys
try:
from Cheetah.Template import Template as CTemplate
@@ -32,6 +33,7 @@ except (ImportError, AttributeError):
from cloudinit import log as logging
from cloudinit import type_utils as tu
from cloudinit import util
+from cloudinit.atomic_helper import write_file
LOG = logging.getLogger(__name__)
TYPE_MATCHER = re.compile(r"##\s*template:(.*)", re.I)
@@ -180,4 +182,17 @@ def render_string(content, params):
return renderer(content, params)
+def render_cloudcfg(variant, template, output):
+
+ with open(template, "r") as fh:
+ contents = fh.read()
+ tpl_params = {"variant": variant}
+ contents = (render_string(contents, tpl_params)).rstrip() + "\n"
+ util.load_yaml(contents)
+ if output == "-":
+ sys.stdout.write(contents)
+ else:
+ write_file(output, contents, omode="w")
+
+
# vi: ts=4 expandtab