Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions conf/master
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,22 @@
# The renderer to use on the minions to render the state data
#renderer: yaml_jinja

# The Jinja renderer can accept Line Statements and/or Line Comments if
# configured with a prefix for each.
# See http://jinja.pocoo.org/docs/templates/#line-statements
#
# If this is set to a string that is not empty, any line starting with this prefix
# will be interpreted as a line statement by the jinja renderer.
# This is set to '#' in the Jinja documentation's examples.
# Defaults to ''.
#jinja_line_statement_prefix: ''
#
# If this is set to a string that is not empty, any line starting with this prefix
# will be interpreted as a line comment statement by the jinja renderer.
# This is set to '##' in the Jinja documentation's examples.
# Defaults to ''.
#jinja_line_comment_prefix: ''

# The Jinja renderer can strip extra carriage returns and whitespace
# See http://jinja.pocoo.org/docs/api/#high-level-api
#
Expand Down
16 changes: 16 additions & 0 deletions conf/suse/master
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,22 @@ syndic_user: salt
# The renderer to use on the minions to render the state data
#renderer: yaml_jinja

# The Jinja renderer can accept Line Statements and/or Line Comments if
# configured with a prefix for each.
# See http://jinja.pocoo.org/docs/templates/#line-statements
#
# If this is set to a string that is not empty, any line starting with this prefix
# will be interpreted as a line statement by the jinja renderer.
# This is set to '#' in the Jinja documentation's examples.
# Defaults to ''.
#jinja_line_statement_prefix: ''
#
# If this is set to a string that is not empty, any line starting with this prefix
# will be interpreted as a line comment statement by the jinja renderer.
# This is set to '##' in the Jinja documentation's examples.
# Defaults to ''.
#jinja_line_comment_prefix: ''

# The Jinja renderer can strip extra carriage returns and whitespace
# See http://jinja.pocoo.org/docs/api/#high-level-api
#
Expand Down
36 changes: 36 additions & 0 deletions doc/ref/configuration/master.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,42 @@ the cloud profile or master config file, no templating will be performed.

userdata_template: jinja

.. conf_master:: jinja_line_statement_prefix

``jinja_line_statement_prefix``
---------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend the dashed line to match the length of the line above. Using different lengths won't make docs builds fail, but it will muddy the output with a warning.


.. versionadded:: Oxygen

Default: ``''``

If this is set to a string that is not empty, any line starting with this prefix
will be interpreted as a line statement by the jinja renderer.
Defaults to ``''`` and corresponds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'' dont corespond with and commented variant above "#"
also I don't find '' anyway usefull thant "#". Instead of I would suggest % as the char. is there anything agains % or %% ? I think it would be more close to today practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the documentation (including this file) is outdated with the code and I will likely have to rewrite most of it. The # and ## suggestions were just pulled from the example in the jinja documentation but I agree that % and %% would be much better for sls files. The only conflict I see is that % is used for yaml directives but I don't think they are used often (if at all) in salt's sls files. Will change the suggestions to use % and %%.

to the Jinja environment init variable ``line_statement_prefix``.

.. code-block:: yaml

jinja_line_statement_prefix: ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see here example from my PR.
(it took me some time to find what really works - not not everything works)


.. conf_master:: jinja_line_comment_prefix

``jinja_line_comment_prefix``
---------------------
Copy link
Contributor

@terminalmage terminalmage Sep 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with the dashed line.


.. versionadded:: Oxygen

Default: ``''``

If this is set to a string that is not empty, any line starting with this prefix
will be interpreted as a line comment by the jinja renderer.
Defaults to ``''`` and corresponds
to the Jinja environment init variable ``line_comment_prefix``.

.. code-block:: yaml

jinja_line_comment_prefix: ''

.. conf_master:: jinja_trim_blocks

``jinja_trim_blocks``
Expand Down
10 changes: 10 additions & 0 deletions salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,14 @@ def _gather_buffer_space():
# check in with their lists of expected minions before giving up
'syndic_wait': int,

# If this is set to a string that is not empty, any line starting with this prefix
# will be interpreted as a line statement by the jinja renderer.
'jinja_line_statement_prefix': str,

# If this is set to a string that is not empty, any line starting with this prefix
# will be interpreted as a line comment statement by the jinja renderer.
'jinja_line_comment_prefix': str,

# If this is set to True leading spaces and tabs are stripped from the start
# of a line to a block.
'jinja_lstrip_blocks': bool,
Expand Down Expand Up @@ -1578,6 +1586,8 @@ def _gather_buffer_space():
'winrepo_passphrase': '',
'winrepo_refspecs': _DFLT_REFSPECS,
'syndic_wait': 5,
'jinja_line_statement_prefix': '',
'jinja_line_comment_prefix': '',
'jinja_lstrip_blocks': False,
'jinja_trim_blocks': False,
'tcp_keepalive': True,
Expand Down
2 changes: 2 additions & 0 deletions salt/daemons/masterapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ def _master_opts(self, load):
mopts['state_auto_order'] = self.opts['state_auto_order']
mopts['state_events'] = self.opts['state_events']
mopts['state_aggregate'] = self.opts['state_aggregate']
mopts['jinja_line_statement_prefix'] = self.opts['jinja_line_statement_prefix']
mopts['jinja_line_comment_prefix'] = self.opts['jinja_line_comment_prefix']
mopts['jinja_lstrip_blocks'] = self.opts['jinja_lstrip_blocks']
mopts['jinja_trim_blocks'] = self.opts['jinja_trim_blocks']
return mopts
Expand Down
2 changes: 2 additions & 0 deletions salt/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ def _master_opts(self, load):
mopts[u'state_auto_order'] = self.opts[u'state_auto_order']
mopts[u'state_events'] = self.opts[u'state_events']
mopts[u'state_aggregate'] = self.opts[u'state_aggregate']
mopts[u'jinja_line_statement_prefix'] = self.opts[u'jinja_line_statement_prefix']
mopts[u'jinja_line_comment_prefix'] = self.opts[u'jinja_line_comment_prefix']
mopts[u'jinja_lstrip_blocks'] = self.opts[u'jinja_lstrip_blocks']
mopts[u'jinja_trim_blocks'] = self.opts[u'jinja_trim_blocks']
return mopts
Expand Down
2 changes: 2 additions & 0 deletions salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,8 @@ def __gen_opts(self, opts):
opts[u'default_top'] = mopts.get(u'default_top', opts.get(u'default_top'))
opts[u'state_events'] = mopts.get(u'state_events')
opts[u'state_aggregate'] = mopts.get(u'state_aggregate', opts.get(u'state_aggregate', False))
opts[u'jinja_line_statement_prefix'] = mopts.get(u'jinja_line_statement_prefix', '')
opts[u'jinja_line_comment_prefix'] = mopts.get(u'jinja_line_comment_prefix', '')
opts[u'jinja_lstrip_blocks'] = mopts.get(u'jinja_lstrip_blocks', False)
opts[u'jinja_trim_blocks'] = mopts.get(u'jinja_trim_blocks', False)
return opts
Expand Down
11 changes: 11 additions & 0 deletions salt/utils/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
env_args['extensions'].append('jinja2.ext.loopcontrols')
env_args['extensions'].append(salt.utils.jinja.SerializerExtension)

# Pass through line_statement_prefix and line_comment_prefix to the jinja environment.
jinja_line_statement_prefix = opts.get('jinja_line_statement_prefix', '')
if jinja_line_statement_prefix:
log.debug('Jinja2 line_statement_prefix is {}'.format(jinja_line_statement_prefix))
env_args['line_statement_prefix'] = jinja_line_statement_prefix

jinja_line_comment_prefix = opts.get('jinja_line_comment_prefix', '')
if jinja_line_comment_prefix:
log.debug('Jinja2 line_comment_prefix is {}'.format(jinja_line_comment_prefix))
env_args['line_comment_prefix'] = jinja_line_comment_prefix

# 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
Expand Down