mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 08:35:21 +00:00
Extend support for pillarenv_from_saltenv to master config
`pillarenv_from_saltenv` is already an option for minion config, this change enables this feature on the master. If set to `true` salt will derive the pillar environment set on the master: $ salt-run pillar.show_pillar saltenv=radman my_passphrase: XYZ $ sudo salt-run pillar.show_pillar saltenv=radman2 my_passphrase: ABC
This commit is contained in:
parent
04bf3af6bb
commit
9b5d28df0c
@ -731,6 +731,11 @@
|
||||
# Recursively merge lists by aggregating them instead of replacing them.
|
||||
#pillar_merge_lists: False
|
||||
|
||||
# Set this option to True to force the pillarenv to be the same as the effective
|
||||
# saltenv when running states. If pillarenv is specified this option will be
|
||||
# ignored.
|
||||
#pillarenv_from_saltenv: False
|
||||
|
||||
# Set this option to 'True' to force a 'KeyError' to be raised whenever an
|
||||
# attempt to retrieve a named value from pillar fails. When this option is set
|
||||
# to 'False', the failed attempt returns an empty string. Default is 'False'.
|
||||
|
@ -2530,6 +2530,27 @@ ext_pillar keys to override those from :conf_master:`pillar_roots`.
|
||||
|
||||
ext_pillar_first: False
|
||||
|
||||
.. conf_minion:: pillarenv_from_saltenv
|
||||
|
||||
``pillarenv_from_saltenv``
|
||||
--------------------------
|
||||
|
||||
Default: ``False``
|
||||
|
||||
When set to ``True``, the :conf_master:`pillarenv` value will assume the value
|
||||
of the effective saltenv when running states. This essentially makes ``salt-run
|
||||
pillar.show_pillar saltenv=dev`` equivalent to ``salt-run pillar.show_pillar
|
||||
saltenv=dev pillarenv=dev``. If :conf_master:`pillarenv` is set on the CLI, it
|
||||
will override this option.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
pillarenv_from_saltenv: True
|
||||
|
||||
.. note::
|
||||
For salt remote execution commands this option should be set in the Minion
|
||||
configuration instead.
|
||||
|
||||
.. conf_master:: pillar_raise_on_missing
|
||||
|
||||
``pillar_raise_on_missing``
|
||||
|
@ -270,6 +270,9 @@ class Pillar(object):
|
||||
def __init__(self, opts, grains, minion_id, saltenv, ext=None, functions=None,
|
||||
pillar=None, pillarenv=None, rend=None):
|
||||
self.minion_id = minion_id
|
||||
if pillarenv is None:
|
||||
if opts.get('pillarenv_from_saltenv', False):
|
||||
opts['pillarenv'] = saltenv
|
||||
# Store the file_roots path so we can restore later. Issue 5449
|
||||
self.actual_file_roots = opts['file_roots']
|
||||
# use the local file client
|
||||
|
@ -24,6 +24,25 @@ import salt.pillar
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class PillarTestCase(TestCase):
|
||||
|
||||
@patch('salt.pillar.compile_template')
|
||||
def test_pillarenv_from_saltenv(self, compile_template):
|
||||
opts = {
|
||||
'renderer': 'json',
|
||||
'renderer_blacklist': [],
|
||||
'renderer_whitelist': [],
|
||||
'state_top': '',
|
||||
'pillar_roots': ['dev', 'base'],
|
||||
'file_roots': ['dev', 'base'],
|
||||
'extension_modules': '',
|
||||
'pillarenv_from_saltenv': True
|
||||
}
|
||||
grains = {
|
||||
'os': 'Ubuntu',
|
||||
}
|
||||
pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'dev')
|
||||
self.assertEqual(pillar.opts['environment'], 'dev')
|
||||
self.assertEqual(pillar.opts['pillarenv'], 'dev')
|
||||
|
||||
@patch('salt.pillar.compile_template')
|
||||
def test_malformed_pillar_sls(self, compile_template):
|
||||
opts = {
|
||||
@ -135,7 +154,7 @@ class PillarTestCase(TestCase):
|
||||
self.assertEqual(pillar.compile_pillar()['ssh'], 'foo')
|
||||
|
||||
def _setup_test_topfile_mocks(self, Matcher, get_file_client,
|
||||
nodegroup_order, glob_order):
|
||||
nodegroup_order, glob_order):
|
||||
# Write a simple topfile and two pillar state files
|
||||
self.top_file = tempfile.NamedTemporaryFile()
|
||||
s = '''
|
||||
|
Loading…
Reference in New Issue
Block a user