mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Implement #8333
This commit is contained in:
parent
20837851f2
commit
236a1656d3
3 changed files with 30 additions and 0 deletions
13
conf/master
13
conf/master
|
@ -225,6 +225,19 @@
|
|||
# The renderer to use on the minions to render the state data
|
||||
#renderer: yaml_jinja
|
||||
|
||||
# The Jinja renderer can strip extra carriage returns and whitespace
|
||||
# See http://jinja.pocoo.org/docs/api/#high-level-api
|
||||
#
|
||||
# If this is set to True the first newline after a Jinja block is removed
|
||||
# (block, not variable tag!). Defaults to False, corresponds to the Jinja
|
||||
# environment init variable "trim_blocks".
|
||||
# jinja_trim_blocks: False
|
||||
#
|
||||
# If this is set to True leading spaces and tabs are stripped from the start
|
||||
# of a line to a block. Defaults to False, corresponds to the Jinja
|
||||
# environment init variable "lstrip_blocks".
|
||||
# jinja_lstrip_blocks: False
|
||||
|
||||
# The failhard option tells the minions to stop immediately after the first
|
||||
# failure detected in the state execution, defaults to False
|
||||
#failhard: False
|
||||
|
|
|
@ -169,6 +169,8 @@ VALID_OPTS = {
|
|||
'grains_refresh_every': int,
|
||||
'enable_lspci': bool,
|
||||
'syndic_wait': int,
|
||||
'jinja_lstrip_blocks': bool,
|
||||
'jinja_trim_blocks': bool,
|
||||
}
|
||||
|
||||
# default configurations
|
||||
|
@ -363,6 +365,8 @@ DEFAULT_MASTER_OPTS = {
|
|||
'win', 'repo', 'winrepo.p'),
|
||||
'win_gitrepos': ['https://github.com/saltstack/salt-winrepo.git'],
|
||||
'syndic_wait': 1,
|
||||
'jinja_lstrip_blocks': False,
|
||||
'jinja_trim_blocks': False,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
|
|||
loader = None
|
||||
newline = False
|
||||
|
||||
|
||||
if tmplstr and not isinstance(tmplstr, unicode):
|
||||
# http://jinja.pocoo.org/docs/api/#unicode
|
||||
tmplstr = tmplstr.decode(SLS_ENCODING)
|
||||
|
@ -143,6 +144,18 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
|
|||
env_args['extensions'].append('jinja2.ext.loopcontrols')
|
||||
env_args['extensions'].append(JinjaSerializerExtension)
|
||||
|
||||
# Pass through trim_blocks and lstrip_blocks Jinja parameters
|
||||
# trim_blocks removes newlines around Jinja blocks
|
||||
# lstrip_blocks strips tabs and spaces from the beginning of
|
||||
# line to the start of a block.
|
||||
|
||||
if opts.get('pillar').get('master').get('jinja_trim_blocks'):
|
||||
log.debug('Jinja2 trim_blocks is enabled')
|
||||
env_args['trim_blocks'] = True
|
||||
if opts.get('pillar').get('master').get('jinja_lstrip_blocks'):
|
||||
log.debug('Jinja2 lstrip_blocks is enabled')
|
||||
env_args['lstrip_blocks'] = True
|
||||
|
||||
if opts.get('allow_undefined', False):
|
||||
jinja_env = jinja2.Environment(**env_args)
|
||||
else:
|
||||
|
|
Loading…
Add table
Reference in a new issue