From 01e922aa693fe60bc7045933ffd9e6189fbc4265 Mon Sep 17 00:00:00 2001 From: Aleksej Romanov Date: Thu, 4 Oct 2012 03:11:14 +0700 Subject: [PATCH] Indicate errors with exit code. --- bin/ansible | 5 +++++ bin/ansible-playbook | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/bin/ansible b/bin/ansible index 2117abd1d0..906bfe5bbc 100755 --- a/bin/ansible +++ b/bin/ansible @@ -127,6 +127,11 @@ if __name__ == '__main__': (options, args) = cli.parse() try: (runner, results) = cli.run(options, args) + for result in results['contacted'].values(): + if 'failed' in result or result.get('rc', 0) != 0: + sys.exit(1) + if results['dark']: + sys.exit(1) except errors.AnsibleError, e: # Generic handler for ansible specific errors print "ERROR: %s" % str(e) diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 2332e08567..954d2c3241 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -140,6 +140,10 @@ def main(args): colorize('failed', t['failures'], 'red')) print "\n" + for h in hosts: + stats = pb.stats.summarize(h) + if stats['failures'] != 0 or stats['unreachable'] != 0: + sys.exit(1) except errors.AnsibleError, e: print >>sys.stderr, "ERROR: %s" % e