win_reboot: survive an already scheduled shutdown

These changes ensure win_reboot can survive an already scheduled
shutdown by pre-empting it.

This fixes #19982
This commit is contained in:
Dag Wieers 2017-01-10 11:56:38 +01:00
commit 239e2ae7e9
2 changed files with 18 additions and 4 deletions

View file

@ -83,9 +83,21 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars)
# initiate reboot
# Initiate reboot
(rc, stdout, stderr) = self._connection.exec_command('shutdown /r /t %d /c "%s"' % (pre_reboot_delay_sec, msg))
# Test for "A system shutdown has already been scheduled. (1190)" and handle it gracefully
if rc == 1190:
result['warnings'] = ( 'A scheduled reboot was pre-empted by Ansible.' )
# Try to abort (this may fail if it was already aborted)
(rc, stdout1, stderr1) = self._connection.exec_command('shutdown /a')
# Initiate reboot again
(rc, stdout2, stderr2) = self._connection.exec_command('shutdown /r /t %d' % pre_reboot_delay_sec)
stdout += stdout1 + stdout2
stderr += stderr1 + stderr2
if rc != 0:
result['failed'] = True
result['rebooted'] = False