Bugfix to check-mode and async support, and features (#28448)

This PR includes:

- Check-mode support, the module will now report as if it was rebooted,
  without making the actual reboot.
- Async-support, this potentially fixes #23835
- The module now also returns the elapsed time, like the wait_for and wait_for_connection modules.
  This fixes #18108
- Add post_reboot_delay_sec parameter
This commit is contained in:
Dag Wieers 2017-08-29 23:44:50 +02:00 committed by Matt Davis
parent 470044f2c5
commit eed6a724ea
3 changed files with 48 additions and 54 deletions

View file

@ -22,7 +22,6 @@ __metaclass__ = type
import time
from datetime import datetime, timedelta
from ansible.module_utils.pycompat24 import get_exception
from ansible.plugins.action import ActionBase
try:
@ -47,19 +46,19 @@ class ActionModule(ActionBase):
def do_until_success_or_timeout(self, what, timeout, connect_timeout, what_desc, sleep=1):
max_end_time = datetime.utcnow() + timedelta(seconds=timeout)
e = None
while datetime.utcnow() < max_end_time:
try:
what(connect_timeout)
if what_desc:
display.debug("wait_for_connection: %s success" % what_desc)
return
except Exception:
e = get_exception()
except Exception as e:
if what_desc:
display.debug("wait_for_connection: %s fail (expected), retrying in %d seconds..." % (what_desc, sleep))
time.sleep(sleep)
raise TimedOutException("timed out waiting for %s: %s" % (what_desc, str(e)))
raise TimedOutException("timed out waiting for %s: %s" % (what_desc, e))
def run(self, tmp=None, task_vars=None):
if task_vars is None:
@ -108,8 +107,7 @@ class ActionModule(ActionBase):
# Use the ping module test to determine end-to-end connectivity
self.do_until_success_or_timeout(ping_module_test, timeout, connect_timeout, what_desc="ping module test success", sleep=sleep)
except TimedOutException:
e = get_exception()
except TimedOutException as e:
result['failed'] = True
result['msg'] = str(e)