summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMichael DeHaan <michael@ansibleworks.com>2013-04-07 23:37:10 -0400
committerMichael DeHaan <michael@ansibleworks.com>2013-04-07 23:37:10 -0400
commitc695aa2d6a4c8cff861b4b14245107c1de049750 (patch)
treeaa4c965823ae3e6b01981b5f7f2293b782b443bd /bin
parentca71eb8cfce3087665634cf9cd778fa9715c8579 (diff)
downloadansible-c695aa2d6a4c8cff861b4b14245107c1de049750.tar.gz
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.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ansible-playbook23
1 files changed, 17 insertions, 6 deletions
diff --git a/bin/ansible-playbook b/bin/ansible-playbook
index a80bbf6ab8..a4de6e42db 100755
--- a/bin/ansible-playbook
+++ b/bin/ansible-playbook
@@ -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