Fix for dynamic git_pillar when pillarenv is used

This fixes an issue in which using a pillarenv would cause dynamic
pillar to be empty. It also corrects an incorrect implementtion
(originally added in 2016.11.1) of an argument added to the pillar.items
function to specify an environment. The argument should have been
pillarenv, and not saltenv.
This commit is contained in:
Erik Johnson 2017-01-12 17:37:02 -06:00
parent cfd82d1631
commit 12bbea5a24
3 changed files with 30 additions and 9 deletions

View file

@ -124,14 +124,14 @@ def items(*args, **kwargs):
.. versionadded:: 2015.5.0
saltenv
pillarenv
Pass a specific pillar environment from which to compile pillar data.
If unspecified, the minion's :conf_minion:`environment` option is used,
and if that also is not specified then all configured pillar
If not specified, then the minion's :conf_minion:`pillarenv` option is
not used, and if that also is not specified then all configured pillar
environments will be merged into a single pillar dictionary and
returned.
.. versionadded:: Nitrogen
.. versionadded:: 2016.11.2
CLI Example:
@ -147,8 +147,8 @@ def items(*args, **kwargs):
__opts__,
__grains__,
__opts__['id'],
kwargs.get('saltenv') or __opts__['environment'],
pillar=kwargs.get('pillar'))
pillar=kwargs.get('pillar'),
pillarenv=kwargs.get('pillarenv') or __opts__['pillarenv'])
return pillar.compile_pillar()

View file

@ -222,8 +222,23 @@ per-remote parameter:
- production https://gitserver/git-pillar.git:
- env: prod
If ``__env__`` is specified as the branch name, then git_pillar will use the
branch specified by :conf_master:`git_pillar_base`:
If ``__env__`` is specified as the branch name, then git_pillar will decide
which branch to use based on the following criteria:
- If the minion has a :conf_minion:`pillarenv` configured, it will use that
pillar environment. (2016.11.2 and later)
- Otherwise, if the minion has an ``environment`` configured, it will use that
environment.
- Otherwise, the master's :conf_master:`git_pillar_base` will be used.
.. note::
The use of :conf_minion:`environment` to choose the pillar environment
dates from a time before the :conf_minion:`pillarenv` parameter was added.
In a future release, it will be ignored and either the minion's
:conf_minion:`pillarenv` or the master's :conf_master:`git_pillar_base`
will be used.
Here's an example of using ``__env__`` as the git_pillar environment:
.. code-block:: yaml
@ -388,6 +403,10 @@ def ext_pillar(minion_id, repo, pillar_dirs):
# the pillar top.sls is sourced from the correct location.
pillar_roots = [pillar_dir]
pillar_roots.extend([x for x in all_dirs if x != pillar_dir])
if env == '__env__':
env = opts.get('pillarenv') \
or opts.get('environment') \
or opts.get('git_pillar_base')
opts['pillar_roots'] = {env: pillar_roots}
local_pillar = Pillar(opts, __grains__, minion_id, env)

View file

@ -666,7 +666,9 @@ class GitProvider(object):
Resolve dynamically-set branch
'''
if self.branch == '__env__':
target = self.opts.get('environment') or 'base'
target = self.opts.get('pillarenv') \
or self.opts.get('environment') \
or 'base'
return self.opts['{0}_base'.format(self.role)] \
if target == 'base' \
else target