mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
7d51b2a6d2
commit
0c3216c565
3 changed files with 21 additions and 11 deletions
|
@ -134,7 +134,16 @@ class ActionModule(ActionBase):
|
||||||
def run_test_command(self, **kwargs):
|
def run_test_command(self, **kwargs):
|
||||||
test_command = self._task.args.get('test_command', self.DEFAULT_TEST_COMMAND)
|
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))
|
display.vvv("%s: attempting post-reboot test command '%s'" % (self._task.action, test_command))
|
||||||
command_result = self._low_level_execute_command(test_command, sudoable=self.DEFAULT_SUDOABLE)
|
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 = {}
|
result = {}
|
||||||
if command_result['rc'] != 0:
|
if command_result['rc'] != 0:
|
||||||
|
|
|
@ -50,33 +50,34 @@ class ActionModule(RebootActionModule, ActionBase):
|
||||||
|
|
||||||
remote_command = self.construct_command()
|
remote_command = self.construct_command()
|
||||||
reboot_result = self._low_level_execute_command(remote_command, sudoable=self.DEFAULT_SUDOABLE)
|
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)))
|
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
|
# 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.')
|
display.warning('A scheduled reboot was pre-empted by Ansible.')
|
||||||
|
|
||||||
# Try to abort (this may fail if it was already aborted)
|
# 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('shutdown /a', sudoable=self.DEFAULT_SUDOABLE)
|
||||||
# (reboot_result['rc'], stdout1, stderr1) = self._connection.exec_command('shutdown /a')
|
|
||||||
|
|
||||||
# Initiate reboot again
|
# Initiate reboot again
|
||||||
result2 = 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)
|
||||||
# (reboot_result['rc'], stdout2, stderr2) = self._connection.exec_command('shutdown /r /t %d' % pre_reboot_delay)
|
|
||||||
|
|
||||||
stdout = reboot_result['stdout'] + result1['stdout'] + result2['stdout']
|
reboot_result['rc'] = result2['rc']
|
||||||
stderr = reboot_result['stderr'] + result1['stderr'] + result2['stderr']
|
stdout += result1['stdout'] + result2['stdout']
|
||||||
|
stderr += result1['stderr'] + result2['stderr']
|
||||||
|
|
||||||
result = {}
|
|
||||||
if reboot_result['rc'] != 0:
|
if reboot_result['rc'] != 0:
|
||||||
result['failed'] = True
|
result['failed'] = True
|
||||||
result['rebooted'] = False
|
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
|
return result
|
||||||
|
|
||||||
result['failed'] = False
|
result['failed'] = False
|
||||||
result['start'] = datetime.utcnow()
|
|
||||||
|
|
||||||
# Get the original connection_timeout option var so it can be reset after
|
# Get the original connection_timeout option var so it can be reset after
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
ansible_password: '{{standard_pass}}'
|
ansible_password: '{{standard_pass}}'
|
||||||
ansible_winrm_transport: ntlm
|
ansible_winrm_transport: ntlm
|
||||||
register: fail_shutdown
|
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:
|
always:
|
||||||
- name: set the original SDDL to the WinRM listener
|
- name: set the original SDDL to the WinRM listener
|
||||||
|
|
Loading…
Reference in a new issue