mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Doc updates, typo fixes. Add -s option for template renderers.
This commit is contained in:
parent
71efcf68d7
commit
bc1183924f
7 changed files with 56 additions and 23 deletions
|
@ -47,7 +47,7 @@ The first line is a shebang that references the ``py`` renderer.
|
|||
|
||||
Composing Renderers
|
||||
-------------------
|
||||
A render can be composed from other renderers by connecting them in a series
|
||||
A renderer can be composed from other renderers by connecting them in a series
|
||||
of pipes(``|``). In fact, the default ``Jinja + YAML`` renderer is implemented
|
||||
by combining a yaml renderer and a jinja renderer. Such renderer configuration
|
||||
is specified as: ``jinja | yaml``.
|
||||
|
@ -61,7 +61,7 @@ Other renderer combinations are possible, here's a few examples:
|
|||
pass the input to the ``mako`` renderer, whose output is then fed into the
|
||||
``yaml`` renderer.
|
||||
|
||||
``jinja | mako | yaml``
|
||||
``jinja | mako -s | yaml``
|
||||
This one allows you to use both jinja and mako templating syntax in the
|
||||
input and then parse the final rendererd output as YAML.
|
||||
|
||||
|
@ -102,8 +102,9 @@ Here is a simple YAML renderer example:
|
|||
.. code-block:: python
|
||||
|
||||
import yaml
|
||||
def render(yaml_data, env='', sls='', argline='', **kws):
|
||||
def render(yaml_data, env='', sls='', **kws):
|
||||
if not isinstance(yaml_data, basestring):
|
||||
yaml_data = yaml_data.read()
|
||||
data = yaml.load(yaml_data)
|
||||
return data if data else {}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
'''
|
||||
The default templating engine, process yaml with the jinja2 templating engine.
|
||||
The default templating engine, process sls file with the jinja2 templating engine.
|
||||
|
||||
This renderer will take a yaml file with the jinja2 template and render it to a
|
||||
yaml string.
|
||||
This renderer will take a sls file authored as a jinja2 template, render it, and
|
||||
return the rendered result as a string.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
@ -12,12 +12,24 @@ import salt.utils.templates
|
|||
|
||||
|
||||
|
||||
def render(template_file, env='', sls='', context=None, **kws):
|
||||
def render(template_file, env='', sls='', argline='', context=None, **kws):
|
||||
'''
|
||||
Render the template_file, passing the functions and grains into the
|
||||
rendering system. Return rendered content as a string.
|
||||
|
||||
Renderer options:
|
||||
|
||||
-s Interpret renderer input as a string rather than as a file path.
|
||||
|
||||
'''
|
||||
tmp_data = salt.utils.templates.jinja(template_file, to_str=True,
|
||||
if argline == '-s':
|
||||
from_str = True
|
||||
elif argline:
|
||||
raise SaltRenderError(
|
||||
'Unknown renderer option: {opt}'.format(opt=argline)
|
||||
)
|
||||
tmp_data = salt.utils.templates.jinja(
|
||||
template_file, from_str, to_str=True,
|
||||
salt=__salt__,
|
||||
grains=__grains__,
|
||||
opts=__opts__,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
import json
|
||||
|
||||
def render(json_data, env='', sls='', **kws):
|
||||
def render(json_data, env='', sls='', argline='', **kws):
|
||||
if not isinstance(json_data, basestring):
|
||||
json_data = json_data.read()
|
||||
|
||||
|
|
|
@ -3,8 +3,21 @@ from __future__ import absolute_import
|
|||
import salt.utils.templates
|
||||
from salt.exceptions import SaltRenderError
|
||||
|
||||
def render(template_file, env='', sls='', context=None, **kws):
|
||||
tmp_data = salt.utils.templates.mako(template_file, to_str=True,
|
||||
def render(template_file, env='', sls='', argline='', context=None, **kws):
|
||||
'''
|
||||
Renderer options:
|
||||
|
||||
-s Interpret renderer input as a string rather than as a file path.
|
||||
|
||||
'''
|
||||
if argline == '-s':
|
||||
from_str = True
|
||||
elif argline:
|
||||
raise SaltRenderError(
|
||||
'Unknown renderer option: {opt}'.format(opt=argline)
|
||||
)
|
||||
tmp_data = salt.utils.templates.mako(
|
||||
template_file, from_str, to_str=True,
|
||||
salt=__salt__,
|
||||
grains=__grains__,
|
||||
opts=__opts__,
|
||||
|
|
|
@ -6,14 +6,6 @@ arguments (including salt specific args, such as 'require', etc) as template
|
|||
context. The goal is to make writing reusable/configurable/ parameterized
|
||||
salt files easier and cleaner, therefore, additionally, it also:
|
||||
|
||||
- Adds support of absolute(eg, ``salt://path/to/salt/file``) and relative(eg,
|
||||
``path/to/salt/file``) template inclusion or import(ie, with ``<%include/>``
|
||||
or ``<%namespace.../>``) for Mako. Example::
|
||||
|
||||
|
||||
<%include file="templates/sls-parts.mako"/>
|
||||
<%namespace file="salt://lib/templates/utils.mako" import="helper"/>
|
||||
|
||||
- Recognizes the special state function, ``stateconf.set``, that configures a
|
||||
default list of named arguments useable within the template context of
|
||||
the salt file. Example::
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
'''
|
||||
Process yaml with the Wempy templating engine
|
||||
Process a sls file with the Wempy templating engine
|
||||
|
||||
'''
|
||||
|
||||
|
@ -11,10 +11,20 @@ import salt.utils.templates
|
|||
def render(template_file, env='', sls='', context=None, **kws):
|
||||
'''
|
||||
Render the data passing the functions and grains into the rendering system
|
||||
|
||||
Renderer options:
|
||||
|
||||
-s Interpret renderer input as a string rather than as a file path.
|
||||
|
||||
'''
|
||||
if argline == '-s':
|
||||
from_str = True
|
||||
elif argline:
|
||||
raise SaltRenderError(
|
||||
'Unknown renderer option: {opt}'.format(opt=argline)
|
||||
)
|
||||
tmp_data = salt.utils.templates.wempy(
|
||||
template_file,
|
||||
True,
|
||||
template_file, from_str, to_str=True,
|
||||
salt=__salt__,
|
||||
grains=__grains__,
|
||||
opts=__opts__,
|
||||
|
@ -24,5 +34,5 @@ def render(template_file, env='', sls='', context=None, **kws):
|
|||
context=context)
|
||||
if not tmp_data.get('result', False):
|
||||
raise SaltRenderError(tmp_data.get('data',
|
||||
'Unknown render error in yaml_wempy renderer'))
|
||||
'Unknown render error in the wempy renderer'))
|
||||
return tmp_data['data']
|
||||
|
|
|
@ -16,6 +16,11 @@ class SaltMakoTemplateLookup(TemplateCollection):
|
|||
If URL is an absolute path then it's treated as if it has been prefixed
|
||||
with salt://.
|
||||
|
||||
Examples::
|
||||
|
||||
<%include file="templates/sls-parts.mako"/>
|
||||
<%namespace file="salt://lib/templates/utils.mako" import="helper"/>
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, opts, env='base'):
|
||||
|
|
Loading…
Add table
Reference in a new issue