Fix unreachable host detection and have plays continue after unreachable failures

Fixes #12284
This commit is contained in:
James Cammarata
2015-09-09 15:26:40 -04:00
parent 25c97fff69
commit be7bd392cb
6 changed files with 17 additions and 11 deletions

View File

@@ -50,6 +50,7 @@ class PlaybookExecutor:
self._display = display
self._options = options
self.passwords = passwords
self._unreachable_hosts = dict()
if options.listhosts or options.listtasks or options.listtags or options.syntax:
self._tqm = None
@@ -121,6 +122,7 @@ class PlaybookExecutor:
else:
# make sure the tqm has callbacks loaded
self._tqm.load_callbacks()
self._tqm._unreachable_hosts.update(self._unreachable_hosts)
# we are actually running plays
for batch in self._get_serialized_batches(new_play):
@@ -148,10 +150,12 @@ class PlaybookExecutor:
break
# clear the failed hosts dictionaires in the TQM for the next batch
self._unreachable_hosts.update(self._tqm._unreachable_hosts)
self._tqm.clear_failed_hosts()
# if the last result wasn't zero, break out of the serial batch loop
if result != 0:
# if the last result wasn't zero or 3 (some hosts were unreachable),
# break out of the serial batch loop
if result not in (0, 3):
break
i = i + 1 # per play
@@ -161,7 +165,7 @@ class PlaybookExecutor:
# if the last result wasn't zero, break out of the playbook file name loop
if result != 0:
break
break
if entrylist:
return entrylist

View File

@@ -28,7 +28,7 @@ import time
from six import iteritems
from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable
from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable, AnsibleConnectionFailure
from ansible.playbook.conditional import Conditional
from ansible.playbook.task import Task
from ansible.template import Templar
@@ -324,7 +324,10 @@ class TaskExecutor:
result['attempts'] = attempt + 1
debug("running the handler")
result = self._handler.run(task_vars=variables)
try:
result = self._handler.run(task_vars=variables)
except AnsibleConnectionFailure as e:
return dict(unreachable=True, msg=str(e))
debug("handler run complete")
if self._task.async > 0:

View File

@@ -222,8 +222,7 @@ class TaskQueueManager:
worker_prc.terminate()
def clear_failed_hosts(self):
self._failed_hosts = dict()
self._unreachable_hosts = dict()
self._failed_hosts = dict()
def get_inventory(self):
return self._inventory