Skip to content

Commit

Permalink
win_reboot: Fix for ignore post_reboot_delay
Browse files Browse the repository at this point in the history
This fixes an issue where win_reboot would be ignoring the provided
post_reboot_delay (and on Windows timing/waiting is everything!)

This must be backported to the v2.7 branch.
  • Loading branch information
dagwieers committed Oct 1, 2018
1 parent 83e5845 commit 528014b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/ansible/plugins/action/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from datetime import datetime, timedelta

from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase
from ansible.module_utils._text import to_native, to_text
from ansible.plugins.action import ActionBase


try:
Expand Down Expand Up @@ -230,7 +230,7 @@ def perform_reboot(self):
except AnsibleError:
display.debug("%s: connect_timeout connection option has not been set" % self._task.action)

post_reboot_delay = int(self._task.args.get('post_reboot_delay', self._task.args.get('post_reboot_delay_sec', self.DEFAULT_POST_REBOOT_DELAY)))
post_reboot_delay = int(self._task.args.get('post_reboot_delay', self.DEFAULT_POST_REBOOT_DELAY))
if post_reboot_delay < 0:
post_reboot_delay = 0

Expand Down
14 changes: 12 additions & 2 deletions lib/ansible/plugins/action/win_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import time
from datetime import datetime

from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase
from ansible.module_utils._text import to_native
from ansible.plugins.action import ActionBase
from ansible.plugins.action.reboot import ActionModule as RebootActionModule

try:
Expand All @@ -29,9 +30,10 @@ class ActionModule(RebootActionModule, ActionBase):
'reboot_timeout', 'reboot_timeout_sec', 'shutdown_timeout', 'shutdown_timeout_sec', 'test_command',
))

DEFAULT_BOOT_TIME_COMMAND = "(Get-WmiObject -ClassName Win32_OperatingSystem).LastBootUpTime"
DEFAULT_CONNECT_TIMEOUT = 5
DEFAULT_PRE_REBOOT_DELAY = 2
DEFAULT_BOOT_TIME_COMMAND = "(Get-WmiObject -ClassName Win32_OperatingSystem).LastBootUpTime"
DEFAULT_POST_REBOOT_DELAY = 0
DEFAULT_SHUTDOWN_COMMAND_ARGS = '/r /t %d /c "%s"'
DEFAULT_SUDOABLE = False

Expand Down Expand Up @@ -89,4 +91,12 @@ def perform_reboot(self):
except AnsibleError:
display.debug("%s: connect_timeout connection option has not been set" % self._task.action)

post_reboot_delay = int(self._task.args.get('post_reboot_delay', self._task.args.get('post_reboot_delay_sec', self.DEFAULT_POST_REBOOT_DELAY)))
if post_reboot_delay < 0:
post_reboot_delay = 0

if post_reboot_delay != 0:
display.vvv("%s: waiting an additional %d seconds" % (self._task.action, post_reboot_delay))
time.sleep(post_reboot_delay)

return result

0 comments on commit 528014b

Please sign in to comment.