From 3d23e47c53caf981fefbbb64d51e07336a93cbf9 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 13 Mar 2019 10:43:02 +1000 Subject: [PATCH] win_reboot - Fix rc validation when using psrp and add extra docs (#53711) * win_reboot - Fix rc validation when using psrp and add extra docs * Revert boot time command and fix docs --- changelogs/fragments/win_reboot-psrp.yaml | 2 ++ lib/ansible/modules/windows/win_reboot.py | 4 ++++ lib/ansible/plugins/action/win_reboot.py | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/win_reboot-psrp.yaml diff --git a/changelogs/fragments/win_reboot-psrp.yaml b/changelogs/fragments/win_reboot-psrp.yaml new file mode 100644 index 00000000000..2325d36fb56 --- /dev/null +++ b/changelogs/fragments/win_reboot-psrp.yaml @@ -0,0 +1,2 @@ +bugfixes: +- win_reboot - Fix reboot command validation failure when running under the psrp connection plugin diff --git a/lib/ansible/modules/windows/win_reboot.py b/lib/ansible/modules/windows/win_reboot.py index f2d44e3e27d..c4097338fec 100644 --- a/lib/ansible/modules/windows/win_reboot.py +++ b/lib/ansible/modules/windows/win_reboot.py @@ -65,6 +65,10 @@ notes: - If a shutdown was already scheduled on the system, C(win_reboot) will abort the scheduled shutdown and enforce its own shutdown. - Beware that when C(win_reboot) returns, the Windows system may not have settled yet and some base services could be in limbo. This can result in unexpected behavior. Check the examples for ways to mitigate this. +- The connection user must have the C(SeRemoteShutdownPrivilege) privilege enabled, see + U(https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/force-shutdown-from-a-remote-system) + for more information. + some Windows hosts. seealso: - module: reboot author: diff --git a/lib/ansible/plugins/action/win_reboot.py b/lib/ansible/plugins/action/win_reboot.py index 4525626d723..d76871d5210 100644 --- a/lib/ansible/plugins/action/win_reboot.py +++ b/lib/ansible/plugins/action/win_reboot.py @@ -49,7 +49,7 @@ class ActionModule(RebootActionModule, ActionBase): def perform_reboot(self, task_vars, distribution): shutdown_command = self.get_shutdown_command(task_vars, distribution) shutdown_command_args = self.get_shutdown_command_args(distribution) - reboot_command = '{0} {1}'.format(shutdown_command, shutdown_command_args) + reboot_command = self._connection._shell._encode_script('{0} {1}'.format(shutdown_command, shutdown_command_args)) display.vvv("{action}: rebooting server...".format(action=self._task.action)) display.debug("{action}: distribution: {dist}".format(action=self._task.action, dist=distribution)) @@ -66,7 +66,8 @@ class ActionModule(RebootActionModule, ActionBase): display.warning('A scheduled reboot was pre-empted by Ansible.') # Try to abort (this may fail if it was already aborted) - result1 = self._low_level_execute_command('shutdown /a', sudoable=self.DEFAULT_SUDOABLE) + result1 = self._low_level_execute_command(self._connection._shell._encode_script('shutdown /a'), + sudoable=self.DEFAULT_SUDOABLE) # Initiate reboot again result2 = self._low_level_execute_command(reboot_command, sudoable=self.DEFAULT_SUDOABLE)