mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Support pillarenv cmdline in state.sls. Backport of PR #23719
This commit is contained in:
parent
207fbaeac4
commit
88ff576f39
5 changed files with 51 additions and 19 deletions
|
@ -1216,7 +1216,8 @@ class AESFuncs(object):
|
|||
load['id'],
|
||||
load.get('saltenv', load.get('env')),
|
||||
ext=load.get('ext'),
|
||||
pillar=load.get('pillar_override', {}))
|
||||
pillar=load.get('pillar_override', {}),
|
||||
pillarenv=load.get('pillarenv'))
|
||||
data = pillar.compile_pillar(pillar_dirs=pillar_dirs)
|
||||
self.fs_.update_opts()
|
||||
if self.opts.get('minion_data_cache', False):
|
||||
|
|
|
@ -331,7 +331,8 @@ class SMinion(object):
|
|||
self.opts,
|
||||
self.opts['grains'],
|
||||
self.opts['id'],
|
||||
self.opts['environment']
|
||||
self.opts['environment'],
|
||||
pillarenv=self.opts.get('pillarenv'),
|
||||
).compile_pillar()
|
||||
self.functions = salt.loader.minion_mods(self.opts, include_errors=True)
|
||||
# TODO: remove
|
||||
|
@ -688,7 +689,8 @@ class Minion(MinionBase):
|
|||
opts,
|
||||
opts['grains'],
|
||||
opts['id'],
|
||||
opts['environment']
|
||||
opts['environment'],
|
||||
pillarenv=opts.get('pillarenv'),
|
||||
).compile_pillar()
|
||||
self.functions, self.returners, self.function_errors = self._load_modules()
|
||||
self.serial = salt.payload.Serial(self.opts)
|
||||
|
@ -1575,6 +1577,7 @@ class Minion(MinionBase):
|
|||
self.opts['grains'],
|
||||
self.opts['id'],
|
||||
self.opts['environment'],
|
||||
pillarenv=self.opts.get('pillarenv'),
|
||||
).compile_pillar()
|
||||
except SaltClientError:
|
||||
# Do not exit if a pillar refresh fails.
|
||||
|
@ -2931,7 +2934,8 @@ class ProxyMinion(Minion):
|
|||
opts,
|
||||
opts['grains'],
|
||||
opts['id'],
|
||||
opts['environment']
|
||||
opts['environment'],
|
||||
pillarenv=opts.get('pillarenv'),
|
||||
).compile_pillar()
|
||||
self.functions, self.returners, self.function_errors = self._load_modules()
|
||||
self.serial = salt.payload.Serial(self.opts)
|
||||
|
|
|
@ -512,6 +512,9 @@ def highstate(test=None,
|
|||
'Pillar data must be formatted as a dictionary'
|
||||
)
|
||||
|
||||
if 'pillarenv' in kwargs:
|
||||
opts['pillarenv'] = kwargs['pillarenv']
|
||||
|
||||
st_ = salt.state.HighState(opts, pillar, kwargs.get('__pub_jid'))
|
||||
st_.push_active()
|
||||
try:
|
||||
|
@ -545,6 +548,7 @@ def sls(mods,
|
|||
exclude=None,
|
||||
queue=False,
|
||||
env=None,
|
||||
pillarenv=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Execute a set list of state files from an environment.
|
||||
|
@ -572,6 +576,9 @@ def sls(mods,
|
|||
Defaults to None. If no saltenv is specified, the minion config will
|
||||
be checked for a saltenv and if found, it will be used. If none is found,
|
||||
base will be used.
|
||||
pillarenv : None
|
||||
Specify a ``pillar_roots`` environment. By default all pillar environments
|
||||
merged together will be used.
|
||||
concurrent:
|
||||
WARNING: This flag is potentially dangerous. It is designed
|
||||
for use when multiple state runs can safely be run at the same
|
||||
|
@ -601,10 +608,18 @@ def sls(mods,
|
|||
# Backwards compatibility
|
||||
saltenv = env
|
||||
if not saltenv:
|
||||
if __opts__.get('saltenv', None):
|
||||
saltenv = __opts__['saltenv']
|
||||
if __opts__.get('environment', None):
|
||||
saltenv = __opts__['environment']
|
||||
else:
|
||||
saltenv = 'base'
|
||||
else:
|
||||
__opts__['environment'] = saltenv
|
||||
|
||||
if not pillarenv:
|
||||
if __opts__.get('pillarenv', None):
|
||||
pillarenv = __opts__['pillarenv']
|
||||
else:
|
||||
__opts__['pillarenv'] = pillarenv
|
||||
|
||||
if queue:
|
||||
_wait(kwargs.get('__pub_jid'))
|
||||
|
@ -849,6 +864,8 @@ def sls_id(
|
|||
opts['test'] = True
|
||||
else:
|
||||
opts['test'] = __opts__.get('test', None)
|
||||
if 'pillarenv' in kwargs:
|
||||
opts['pillarenv'] = kwargs['pillarenv']
|
||||
st_ = salt.state.HighState(opts)
|
||||
if isinstance(mods, string_types):
|
||||
split_mods = mods.split(',')
|
||||
|
@ -911,6 +928,8 @@ def show_low_sls(mods,
|
|||
opts['test'] = True
|
||||
else:
|
||||
opts['test'] = __opts__.get('test', None)
|
||||
if 'pillarenv' in kwargs:
|
||||
opts['pillarenv'] = kwargs['pillarenv']
|
||||
st_ = salt.state.HighState(opts)
|
||||
if isinstance(mods, string_types):
|
||||
mods = mods.split(',')
|
||||
|
@ -972,6 +991,9 @@ def show_sls(mods, saltenv='base', test=None, queue=False, env=None, **kwargs):
|
|||
'Pillar data must be formatted as a dictionary'
|
||||
)
|
||||
|
||||
if 'pillarenv' in kwargs:
|
||||
opts['pillarenv'] = kwargs['pillarenv']
|
||||
|
||||
st_ = salt.state.HighState(opts, pillar)
|
||||
if isinstance(mods, string_types):
|
||||
mods = mods.split(',')
|
||||
|
|
|
@ -28,7 +28,7 @@ log = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def get_pillar(opts, grains, id_, saltenv=None, ext=None, env=None, funcs=None,
|
||||
pillar=None):
|
||||
pillar=None, pillarenv=None):
|
||||
'''
|
||||
Return the correct pillar driver based on the file_client option
|
||||
'''
|
||||
|
@ -45,7 +45,7 @@ def get_pillar(opts, grains, id_, saltenv=None, ext=None, env=None, funcs=None,
|
|||
'local': Pillar
|
||||
}.get(opts['file_client'], Pillar)
|
||||
return ptype(opts, grains, id_, saltenv, ext, functions=funcs,
|
||||
pillar=pillar)
|
||||
pillar=pillar, pillarenv=pillarenv)
|
||||
|
||||
|
||||
class RemotePillar(object):
|
||||
|
@ -53,13 +53,14 @@ class RemotePillar(object):
|
|||
Get the pillar from the master
|
||||
'''
|
||||
def __init__(self, opts, grains, id_, saltenv, ext=None, functions=None,
|
||||
pillar=None):
|
||||
pillar=None, pillarenv=None):
|
||||
self.opts = opts
|
||||
self.opts['environment'] = saltenv
|
||||
self.ext = ext
|
||||
self.grains = grains
|
||||
self.id_ = id_
|
||||
self.channel = salt.transport.Channel.factory(opts)
|
||||
self.opts['pillarenv'] = pillarenv
|
||||
self.pillar_override = {}
|
||||
if pillar is not None:
|
||||
if isinstance(pillar, dict):
|
||||
|
@ -74,6 +75,7 @@ class RemotePillar(object):
|
|||
load = {'id': self.id_,
|
||||
'grains': self.grains,
|
||||
'saltenv': self.opts['environment'],
|
||||
'pillarenv': self.opts['pillarenv'],
|
||||
'pillar_override': self.pillar_override,
|
||||
'ver': '2',
|
||||
'cmd': '_pillar'}
|
||||
|
@ -97,11 +99,11 @@ class Pillar(object):
|
|||
Read over the pillar top files and render the pillar data
|
||||
'''
|
||||
def __init__(self, opts, grains, id_, saltenv, ext=None, functions=None,
|
||||
pillar=None):
|
||||
pillar=None, pillarenv=None):
|
||||
# Store the file_roots path so we can restore later. Issue 5449
|
||||
self.actual_file_roots = opts['file_roots']
|
||||
# use the local file client
|
||||
self.opts = self.__gen_opts(opts, grains, id_, saltenv, ext)
|
||||
self.opts = self.__gen_opts(opts, grains, id_, saltenv=saltenv, ext=ext, pillarenv=pillarenv)
|
||||
self.client = salt.fileclient.get_file_client(self.opts, True)
|
||||
|
||||
if opts.get('file_client', '') == 'local':
|
||||
|
@ -145,7 +147,7 @@ class Pillar(object):
|
|||
return {}
|
||||
return ext
|
||||
|
||||
def __gen_opts(self, opts_in, grains, id_, saltenv=None, ext=None, env=None):
|
||||
def __gen_opts(self, opts_in, grains, id_, saltenv=None, ext=None, env=None, pillarenv=None):
|
||||
'''
|
||||
The options need to be altered to conform to the file client
|
||||
'''
|
||||
|
@ -168,6 +170,8 @@ class Pillar(object):
|
|||
opts['id'] = id_
|
||||
if 'environment' not in opts:
|
||||
opts['environment'] = saltenv
|
||||
if 'pillarenv' not in opts:
|
||||
opts['pillarenv'] = pillarenv
|
||||
if opts['state_top'].startswith('salt://'):
|
||||
opts['state_top'] = opts['state_top']
|
||||
elif opts['state_top'].startswith('/'):
|
||||
|
@ -200,16 +204,16 @@ class Pillar(object):
|
|||
errors = []
|
||||
# Gather initial top files
|
||||
try:
|
||||
if self.opts['environment']:
|
||||
tops[self.opts['environment']] = [
|
||||
if self.opts['pillarenv']:
|
||||
tops[self.opts['pillarenv']] = [
|
||||
compile_template(
|
||||
self.client.cache_file(
|
||||
self.opts['state_top'],
|
||||
self.opts['environment']
|
||||
self.opts['pillarenv']
|
||||
),
|
||||
self.rend,
|
||||
self.opts['renderer'],
|
||||
self.opts['environment'],
|
||||
self.opts['pillarenv'],
|
||||
_pillar_rend=True
|
||||
)
|
||||
]
|
||||
|
@ -343,8 +347,8 @@ class Pillar(object):
|
|||
'''
|
||||
matches = {}
|
||||
for saltenv, body in top.items():
|
||||
if self.opts['environment']:
|
||||
if saltenv != self.opts['environment']:
|
||||
if self.opts['pillarenv']:
|
||||
if saltenv != self.opts['pillarenv']:
|
||||
continue
|
||||
for match, data in body.items():
|
||||
if self.matcher.confirm_top(
|
||||
|
|
|
@ -595,7 +595,8 @@ class State(object):
|
|||
self.opts['grains'],
|
||||
self.opts['id'],
|
||||
self.opts['environment'],
|
||||
pillar=self._pillar_override
|
||||
pillar=self._pillar_override,
|
||||
pillarenv=self.opts.get('pillarenv')
|
||||
)
|
||||
ret = pillar.compile_pillar()
|
||||
if self._pillar_override and isinstance(self._pillar_override, dict):
|
||||
|
|
Loading…
Add table
Reference in a new issue