mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #12832 from whiteinge/salt-jinja-show-context
Added debugging helper function to Jinja to dump available context
This commit is contained in:
commit
11c03559e9
@ -179,6 +179,16 @@ external template file.
|
||||
starting with one or more underscores, and should be managed by one of the
|
||||
following tags: `macro`, `set`, `load_yaml`, `load_json`, `import_yaml` and
|
||||
`import_json`.
|
||||
|
||||
Debugging
|
||||
=========
|
||||
|
||||
The ``show_full_context`` function can be used to output all variables present
|
||||
in the current Jinja context.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
Context is: {{ show_full_context }}
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
@ -15,6 +15,7 @@ from jinja2 import BaseLoader, Markup, TemplateNotFound, nodes
|
||||
from jinja2.environment import TemplateModule
|
||||
from jinja2.ext import Extension
|
||||
from jinja2.exceptions import TemplateRuntimeError
|
||||
import jinja2
|
||||
import yaml
|
||||
|
||||
# Import salt libs
|
||||
@ -187,6 +188,9 @@ def ensure_sequence_filter(data):
|
||||
return [data]
|
||||
return data
|
||||
|
||||
@jinja2.contextfunction
|
||||
def show_full_context(c):
|
||||
return c
|
||||
|
||||
class SerializerExtension(Extension, object):
|
||||
'''
|
||||
|
@ -23,7 +23,7 @@ import salt.utils
|
||||
from salt.exceptions import (
|
||||
SaltRenderError, CommandExecutionError, SaltInvocationError
|
||||
)
|
||||
from salt.utils.jinja import ensure_sequence_filter
|
||||
from salt.utils.jinja import ensure_sequence_filter, show_full_context
|
||||
from salt.utils.jinja import SaltCacheLoader as JinjaSaltCacheLoader
|
||||
from salt.utils.jinja import SerializerExtension as JinjaSerializerExtension
|
||||
from salt.utils.odict import OrderedDict
|
||||
@ -254,6 +254,7 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
|
||||
jinja_env.filters['sequence'] = ensure_sequence_filter
|
||||
|
||||
jinja_env.globals['odict'] = OrderedDict
|
||||
jinja_env.globals['show_full_context'] = show_full_context
|
||||
|
||||
unicode_context = {}
|
||||
for key, value in context.iteritems():
|
||||
|
Loading…
Reference in New Issue
Block a user