mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Allow unless, onlyif, check_cmd to use python_shell=True
This commit is contained in:
parent
eadfc30256
commit
977d9accf0
@ -414,6 +414,11 @@ the specified commands return ``False``. The ``unless`` requisite operates
|
||||
as NOR and is useful in giving more granular control over when a state should
|
||||
execute.
|
||||
|
||||
**NOTE**: Under the hood ``unless`` calls ``cmd.retcode`` with
|
||||
``python_shell=True``. This means the commands referenced by unless will be
|
||||
parsed by a shell, so beware of side-effects as this shell will be run with the
|
||||
same privileges as the salt-minion.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
vim:
|
||||
@ -453,6 +458,11 @@ Onlyif
|
||||
return ``True``, then the state is run. If any of the specified commands
|
||||
return ``False``, the state will not run.
|
||||
|
||||
**NOTE**: Under the hood ``onlyif`` calls ``cmd.retcode`` with
|
||||
``python_shell=True``. This means the commands referenced by unless will be
|
||||
parsed by a shell, so beware of side-effects as this shell will be run with the
|
||||
same privileges as the salt-minion.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
stop-volume:
|
||||
@ -527,6 +537,11 @@ check_cmd
|
||||
Check Command is used for determining that a state did or did not run as
|
||||
expected.
|
||||
|
||||
**NOTE**: Under the hood ``check_cmd`` calls ``cmd.retcode`` with
|
||||
``python_shell=True``. This means the commands referenced by unless will be
|
||||
parsed by a shell, so beware of side-effects as this shell will be run with the
|
||||
same privileges as the salt-minion.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
comment-repo:
|
||||
|
@ -650,7 +650,7 @@ class State(object):
|
||||
else:
|
||||
low_data_onlyif = low_data['onlyif']
|
||||
for entry in low_data_onlyif:
|
||||
cmd = self.functions['cmd.retcode'](entry, ignore_retcode=True, **cmd_opts)
|
||||
cmd = self.functions['cmd.retcode'](entry, ignore_retcode=True, python_shell=True, **cmd_opts)
|
||||
log.debug('Last command return code: {0}'.format(cmd))
|
||||
if cmd != 0 and ret['result'] is False:
|
||||
ret.update({'comment': 'onlyif execution failed',
|
||||
@ -667,7 +667,7 @@ class State(object):
|
||||
else:
|
||||
low_data_unless = low_data['unless']
|
||||
for entry in low_data_unless:
|
||||
cmd = self.functions['cmd.retcode'](entry, ignore_retcode=True, **cmd_opts)
|
||||
cmd = self.functions['cmd.retcode'](entry, ignore_retcode=True, python_shell=True, **cmd_opts)
|
||||
log.debug('Last command return code: {0}'.format(cmd))
|
||||
if cmd == 0 and ret['result'] is False:
|
||||
ret.update({'comment': 'unless execution succeeded',
|
||||
@ -689,7 +689,7 @@ class State(object):
|
||||
if 'shell' in self.opts['grains']:
|
||||
cmd_opts['shell'] = self.opts['grains'].get('shell')
|
||||
for entry in low_data['check_cmd']:
|
||||
cmd = self.functions['cmd.retcode'](entry, ignore_retcode=True, **cmd_opts)
|
||||
cmd = self.functions['cmd.retcode'](entry, ignore_retcode=True, python_shell=True, **cmd_opts)
|
||||
log.debug('Last command return code: {0}'.format(cmd))
|
||||
if cmd == 0 and ret['result'] is False:
|
||||
ret.update({'comment': 'check_cmd determined the state succeeded', 'result': True})
|
||||
|
Loading…
Reference in New Issue
Block a user