Merge branch 'win_reboot-fix' of git://github.com/dagwieers/ansible into HEAD
This commit is contained in:
commit
c8970fc4e6
2 changed files with 18 additions and 4 deletions
lib/ansible
|
@ -57,21 +57,23 @@ options:
|
||||||
description:
|
description:
|
||||||
- Message to display to users
|
- Message to display to users
|
||||||
default: Reboot initiated by Ansible
|
default: Reboot initiated by Ansible
|
||||||
|
notes:
|
||||||
|
- If a shutdown was already scheduled on the system, C(win_reboot) will abort the scheduled shutdown and enforce its own shutdown.
|
||||||
author:
|
author:
|
||||||
- Matt Davis (@nitzmahone)
|
- Matt Davis (@nitzmahone)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES='''
|
EXAMPLES='''
|
||||||
# unconditionally reboot the machine with all defaults
|
# Unconditionally reboot the machine with all defaults
|
||||||
- win_reboot:
|
- win_reboot:
|
||||||
|
|
||||||
# apply updates and reboot if necessary
|
# Apply updates and reboot if necessary
|
||||||
- win_updates:
|
- win_updates:
|
||||||
register: update_result
|
register: update_result
|
||||||
- win_reboot:
|
- win_reboot:
|
||||||
when: update_result.reboot_required
|
when: update_result.reboot_required
|
||||||
|
|
||||||
# reboot a slow machine that might have lots of updates to apply
|
# Reboot a slow machine that might have lots of updates to apply
|
||||||
- win_reboot:
|
- win_reboot:
|
||||||
shutdown_timeout_sec: 3600
|
shutdown_timeout_sec: 3600
|
||||||
reboot_timeout_sec: 3600
|
reboot_timeout_sec: 3600
|
||||||
|
|
|
@ -83,9 +83,21 @@ class ActionModule(ActionBase):
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
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))
|
(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:
|
if rc != 0:
|
||||||
result['failed'] = True
|
result['failed'] = True
|
||||||
result['rebooted'] = False
|
result['rebooted'] = False
|
||||||
|
|
Loading…
Reference in a new issue