win_reboot: fix minor issues with the latest refactor (#44740)

* win_reboot: fix minor issues with the latest refactor

* Always return elapsed with win_reboot
pull/44794/head
Jordan Borean 6 years ago committed by Sam Doran
parent 7d51b2a6d2
commit 0c3216c565

@ -134,7 +134,16 @@ class ActionModule(ActionBase):
def run_test_command(self, **kwargs):
test_command = self._task.args.get('test_command', self.DEFAULT_TEST_COMMAND)
display.vvv("%s: attempting post-reboot test command '%s'" % (self._task.action, test_command))
try:
command_result = self._low_level_execute_command(test_command, sudoable=self.DEFAULT_SUDOABLE)
except Exception:
# may need to reset the connection in case another reboot occurred
# which has invalidated our connection
try:
self._connection.reset()
except AttributeError:
pass
raise
result = {}
if command_result['rc'] != 0:

@ -50,33 +50,34 @@ class ActionModule(RebootActionModule, ActionBase):
remote_command = self.construct_command()
reboot_result = self._low_level_execute_command(remote_command, sudoable=self.DEFAULT_SUDOABLE)
result = {}
result['start'] = datetime.utcnow()
pre_reboot_delay = int(self._task.args.get('pre_reboot_delay', self._task.args.get('pre_reboot_delay_sec', self.DEFAULT_PRE_REBOOT_DELAY)))
# Test for "A system shutdown has already been scheduled. (1190)" and handle it gracefully
if reboot_result['rc'] == 1190 or (reboot_result['rc'] != 0 and b"(1190)" in reboot_result['stderr']):
stdout = reboot_result['stdout']
stderr = reboot_result['stderr']
if reboot_result['rc'] == 1190 or (reboot_result['rc'] != 0 and "(1190)" in reboot_result['stderr']):
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)
# (reboot_result['rc'], stdout1, stderr1) = self._connection.exec_command('shutdown /a')
# Initiate reboot again
result2 = self._connection.exec_command('shutdown /r /t %d' % pre_reboot_delay)
# (reboot_result['rc'], stdout2, stderr2) = self._connection.exec_command('shutdown /r /t %d' % pre_reboot_delay)
result2 = self._low_level_execute_command('shutdown /r /t %d' % pre_reboot_delay, sudoable=self.DEFAULT_SUDOABLE)
stdout = reboot_result['stdout'] + result1['stdout'] + result2['stdout']
stderr = reboot_result['stderr'] + result1['stderr'] + result2['stderr']
reboot_result['rc'] = result2['rc']
stdout += result1['stdout'] + result2['stdout']
stderr += result1['stderr'] + result2['stderr']
result = {}
if reboot_result['rc'] != 0:
result['failed'] = True
result['rebooted'] = False
result['msg'] = "Shutdown command failed, error was: %s %s" % (to_native(stdout.strip()), to_native('stderr'.strip()))
result['msg'] = "Shutdown command failed, error was: %s %s" % (to_native(stdout.strip()), to_native(stderr.strip()))
return result
result['failed'] = False
result['start'] = datetime.utcnow()
# Get the original connection_timeout option var so it can be reset after
try:

@ -66,7 +66,7 @@
ansible_password: '{{standard_pass}}'
ansible_winrm_transport: ntlm
register: fail_shutdown
failed_when: fail_shutdown.msg != "Shutdown command failed, error text was 'Access is denied.(5)\n'"
failed_when: "fail_shutdown.msg != 'Shutdown command failed, error was: Access is denied.(5)'"
always:
- name: set the original SDDL to the WinRM listener

Loading…
Cancel
Save