charmhelpers.core.templating

charmhelpers.core.templating.render(source, target, context, owner='root', group='root', perms=292, templates_dir=None, encoding='UTF-8')

Render a Jinja2 template.

Parameters:
  • source (str) – Path to template, relative to templates_dir.
  • target (str) – Path (generally absolute) to write template to. If None, no file will be written (in case only the returned rendered template string is desired).
  • context (dict) – Variables available to the template.
  • owner (str) – Passed through to write_file().
  • group (str) – Passed through to write_file().
  • perms (str) – Passed through to write_file().
  • templates_dir (str) – Base path for the templates. Defaults to $CHARM_DIR/templates.
  • encoding (str) – Encoding to use when writing the file.
Returns:

The rendered template.

Note: Using this requires python-jinja2; if it is not installed, calling this will attempt to use charmhelpers.fetch.apt_install() to install it.