When playbooks fail, attempt to create an inventory file in the inventory directory that allows rerunning

of the playbook against only the hosts that failed.
This commit is contained in:
Michael DeHaan
2013-04-07 23:37:10 -04:00
parent ca71eb8cfc
commit c695aa2d6a
4 changed files with 109 additions and 6 deletions

View File

@@ -174,6 +174,7 @@ def main(args):
print 'Playbook Syntax is fine'
return 0
failed_hosts = []
try:
@@ -182,6 +183,17 @@ def main(args):
hosts = sorted(pb.stats.processed.keys())
print callbacks.banner("PLAY RECAP")
playbook_cb.on_stats(pb.stats)
for h in hosts:
t = pb.stats.summarize(h)
if t['unreachable'] > 0 or t['failures'] > 0:
failed_hosts.append(h)
if len(failed_hosts) > 0:
filename = pb.generate_retry_inventory(failed_hosts)
if filename:
print " to rerun against failed hosts only, use -i %s\n" % filename
for h in hosts:
t = pb.stats.summarize(h)
print "%s : %s %s %s %s" % (
@@ -190,17 +202,16 @@ def main(args):
colorize('changed', t['changed'], 'yellow'),
colorize('unreachable', t['unreachable'], 'red'),
colorize('failed', t['failures'], 'red'))
print "\n"
for h in hosts:
stats = pb.stats.summarize(h)
if stats['failures'] != 0 or stats['unreachable'] != 0:
return 2
print ""
if len(failed_hosts) > 0:
return 2
except errors.AnsibleError, e:
print >>sys.stderr, "ERROR: %s" % e
return 1
return 0