From 2e56527eada169d5b2ae2b9be8c6469a04a0d638 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Wed, 7 Sep 2016 10:36:13 -0500 Subject: [PATCH] Move command logging to before win_runas With the addition of runas for Windows in 2016.3.0, commands run using Windows runas would not be logged at all, as we would return from the _run() function before we got to the line where this information was logged. This commit moves the command logging up to before we enter the if block where the win_runas code would be executed, restoring the prior logging behavior. --- salt/modules/cmdmod.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index ee590bde68..08eb4f941a 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -303,6 +303,22 @@ def _run(cmd, 'Setting value to an empty string'.format(bad_env_key)) env[bad_env_key] = '' + if _check_loglevel(output_loglevel) is not None: + # Always log the shell commands at INFO unless quiet logging is + # requested. The command output is what will be controlled by the + # 'loglevel' parameter. + msg = ( + 'Executing command {0}{1}{0} {2}in directory \'{3}\'{4}'.format( + '\'' if not isinstance(cmd, list) else '', + cmd, + 'as user \'{0}\' '.format(runas) if runas else '', + cwd, + '. Executing command in the background, no output will be ' + 'logged.' if bg else '' + ) + ) + log.info(log_callback(msg)) + if runas and salt.utils.is_windows(): if not password: msg = 'password is a required argument for runas on Windows' @@ -368,21 +384,6 @@ def _run(cmd, ) ) - if _check_loglevel(output_loglevel) is not None: - # Always log the shell commands at INFO unless quiet logging is - # requested. The command output is what will be controlled by the - # 'loglevel' parameter. - msg = ( - 'Executing command {0}{1}{0} {2}in directory \'{3}\'{4}'.format( - '\'' if not isinstance(cmd, list) else '', - cmd, - 'as user \'{0}\' '.format(runas) if runas else '', - cwd, - ' in the background, no output will be logged' if bg else '' - ) - ) - log.info(log_callback(msg)) - if reset_system_locale is True: if not salt.utils.is_windows(): # Default to C!