diff options
author | James Cammarata <jimi@sngx.net> | 2016-08-24 09:43:55 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2016-08-24 09:43:55 -0500 |
commit | a745b4cb2d743f75123fedf851f8eb87c8a3ac16 (patch) | |
tree | 8f43df77217aa03678c477e2c3f71cee9626a33e | |
parent | 20bde8f549cd11d05fbfbf174f4f3be3c9248374 (diff) | |
download | ansible-improve_async_messages_fix_connection_error_handling.tar.gz |
Prevent connection failures from stopping async pollingimprove_async_messages_fix_connection_error_handling
This patch fixes an issue where an async action might make the system
unreachable for a period of time (ie. during a reboot or network restart).
In addition to the above, this patch uses the retry message callback to
provide status updates of the async polling, though it may require some
additional tweaks to the default callback to prevent the messages from
appearing as failures rather than "job not finished" messages.
-rw-r--r-- | lib/ansible/executor/task_executor.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 7b0802bcb2..f128e0e41a 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -588,7 +588,14 @@ class TaskExecutor: while time_left > 0: time.sleep(self._task.poll) - async_result = normal_handler.run(task_vars=task_vars) + try: + async_result = normal_handler.run(task_vars=task_vars) + except AnsibleConnectionFailure as e: + # set the result to an empty dict to avoid errors below + async_result = dict( + msg="async check failed due to system being unreachable: %s" % e, + ) + # We do not bail out of the loop in cases where the failure # is associated with a parsing error. The async_runner can # have issues which result in a half-written/unparseable result @@ -597,6 +604,9 @@ class TaskExecutor: if int(async_result.get('finished', 0)) == 1 or ('failed' in async_result and async_result.get('_ansible_parsed', False)) or 'skipped' in async_result: break + async_result.update(dict(_ansible_retry=True, retries=time_left, attempts=self._task.poll)) + self._rslt_q.put(TaskResult(self._host.name, self._task._uuid, async_result), block=False) + time_left -= self._task.poll if int(async_result.get('finished', 0)) != 1: |