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:
Pedro Algarvio 2014-05-16 12:44:35 +01:00
commit 11c03559e9
3 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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):
'''

View File

@ -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():