Update PillarStack stack.py to latest upstream version

which provides a fix for Windows minions:
https://github.com/bbinet/pillarstack/pull/29

and the following enhancements:
https://github.com/bbinet/pillarstack/pull/26
https://github.com/bbinet/pillarstack/pull/27
This commit is contained in:
Bruno Binet 2017-04-05 16:16:07 +02:00
parent c98920c5fb
commit 6ed8f6c4ce

View File

@ -377,6 +377,7 @@ You can also select a custom merging strategy using a ``__`` object in a list:
# Import Python libs # Import Python libs
from __future__ import absolute_import from __future__ import absolute_import
import os import os
import posixpath
import logging import logging
from functools import partial from functools import partial
from glob import glob from glob import glob
@ -419,10 +420,19 @@ def ext_pillar(minion_id, pillar, *args, **kwargs):
return stack return stack
def _to_unix_slashes(path):
return posixpath.join(*path.split(os.sep))
def _construct_unicode(loader, node):
return node.value
def _process_stack_cfg(cfg, stack, minion_id, pillar): def _process_stack_cfg(cfg, stack, minion_id, pillar):
log.debug('Config: {0}'.format(cfg)) log.debug('Config: {0}'.format(cfg))
basedir, filename = os.path.split(cfg) basedir, filename = os.path.split(cfg)
jenv = Environment(loader=FileSystemLoader(basedir)) yaml.SafeLoader.add_constructor("tag:yaml.org,2002:python/unicode", _construct_unicode)
jenv = Environment(loader=FileSystemLoader(basedir), extensions=['jinja2.ext.do', salt.utils.jinja.SerializerExtension])
jenv.globals.update({ jenv.globals.update({
"__opts__": __opts__, "__opts__": __opts__,
"__salt__": __salt__, "__salt__": __salt__,
@ -444,8 +454,9 @@ def _process_stack_cfg(cfg, stack, minion_id, pillar):
continue continue
for path in sorted(paths): for path in sorted(paths):
log.debug('YAML: basedir={0}, path={1}'.format(basedir, path)) log.debug('YAML: basedir={0}, path={1}'.format(basedir, path))
obj = yaml.safe_load(jenv.get_template( # FileSystemLoader always expects unix-style paths
os.path.relpath(path, basedir)).render(stack=stack)) unix_path = _to_unix_slashes(os.path.relpath(path, basedir))
obj = yaml.safe_load(jenv.get_template(unix_path).render(stack=stack))
if not isinstance(obj, dict): if not isinstance(obj, dict):
log.info('Ignoring pillar stack template "{0}": Can\'t parse ' log.info('Ignoring pillar stack template "{0}": Can\'t parse '
'as a valid yaml dictionary'.format(path)) 'as a valid yaml dictionary'.format(path))