diff --git a/salt/utils/mako.py b/salt/utils/mako.py index 321dfe981c..80ad9d8df5 100644 --- a/salt/utils/mako.py +++ b/salt/utils/mako.py @@ -44,7 +44,7 @@ class SaltMakoTemplateLookup(TemplateCollection): """ - def __init__(self, opts, saltenv='base', env=None): + def __init__(self, opts, saltenv='base', env=None, pillar_rend=False): if env is not None: salt.utils.warn_until( 'Boron', @@ -56,10 +56,20 @@ class SaltMakoTemplateLookup(TemplateCollection): saltenv = env self.opts = opts self.saltenv = saltenv - self.file_client = salt.fileclient.get_file_client(self.opts) + self._file_client = None + self.pillar_rend = pillar_rend self.lookup = TemplateLookup(directories='/') self.cache = {} + def file_client(self): + ''' + Setup and return file_client + ''' + if not self._file_client: + self._file_client = salt.fileclient.get_file_client( + self.opts, self.pillar_rend) + return self._file_client + def adjust_uri(self, uri, filename): scheme = urlparse(uri).scheme if scheme in ('salt', 'file'): @@ -93,7 +103,7 @@ class SaltMakoTemplateLookup(TemplateCollection): def cache_file(self, fpath): if fpath not in self.cache: - self.cache[fpath] = self.file_client.get_file(fpath, + self.cache[fpath] = self.file_client().get_file(fpath, '', True, self.saltenv) diff --git a/salt/utils/templates.py b/salt/utils/templates.py index ba3aeeb638..9017e8e93c 100644 --- a/salt/utils/templates.py +++ b/salt/utils/templates.py @@ -435,7 +435,10 @@ def render_mako_tmpl(tmplstr, context, tmplpath=None): from mako.lookup import TemplateLookup lookup = TemplateLookup(directories=[os.path.dirname(tmplpath)]) else: - lookup = SaltMakoTemplateLookup(context['opts'], saltenv) + lookup = SaltMakoTemplateLookup( + context['opts'], + saltenv, + pillar_rend=context.get('_pillar_rend', False)) try: return Template( tmplstr,