Merge pull request #16238 from cachedout/pillar_context

Make renderers fully aware of pillar context
This commit is contained in:
Thomas S Hatch 2014-09-29 20:01:53 -06:00
commit 80571cf912
3 changed files with 5 additions and 6 deletions

View File

@ -378,7 +378,7 @@ class Pillar(object):
state = None
try:
state = compile_template(
fn_, self.rend, self.opts['renderer'], saltenv, sls, **defaults)
fn_, self.rend, self.opts['renderer'], saltenv, sls, _pillar_rend=True, **defaults)
except Exception as exc:
msg = 'Rendering SLS {0!r} failed, render error:\n{1}'.format(
sls, exc

View File

@ -51,7 +51,7 @@ class SaltCacheLoader(BaseLoader):
Templates are cached like regular salt states
and only loaded once per loader instance.
'''
def __init__(self, opts, saltenv='base', encoding='utf-8', env=None):
def __init__(self, opts, saltenv='base', encoding='utf-8', env=None, pillar_rend=False):
if env is not None:
salt.utils.warn_until(
'Boron',
@ -71,6 +71,7 @@ class SaltCacheLoader(BaseLoader):
log.debug('Jinja search path: {0!r}'.format(self.searchpath))
self._file_client = None
self.cached = []
self.pillar_rend = pillar_rend
def file_client(self):
'''
@ -79,7 +80,7 @@ class SaltCacheLoader(BaseLoader):
if not self._file_client:
self._file_client = salt.fileclient.get_file_client(
self.opts,
True if self.opts.get('__role') == 'master' else False)
self.pillar_rend)
return self._file_client
def cache_file(self, template):

View File

@ -55,8 +55,6 @@ def wrap_tmpl_func(render_str):
# We want explicit context to overwrite the **kws
kws.update(context)
context = kws
assert 'opts' in context
assert 'saltenv' in context
if isinstance(tmplsrc, string_types):
if from_str:
@ -221,7 +219,7 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
loader = jinja2.FileSystemLoader(
context, os.path.dirname(tmplpath))
else:
loader = JinjaSaltCacheLoader(opts, saltenv)
loader = JinjaSaltCacheLoader(opts, saltenv, pillar_rend=context.get('_pillar_rend', False))
env_args = {'extensions': [], 'loader': loader}