From 2b96c347dce512d30d49f394e3b66f2efbb06daa Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Wed, 14 Aug 2013 13:26:59 -0700 Subject: [PATCH] Exit with status 3 if no failures but unreachable. Provide hints to playbook callers that a playbook execution had unreachable vs failures. 2 == failures, 3 == no failures, but unreachable hosts. 0 continues to be all good. --- bin/ansible | 2 +- bin/ansible-playbook | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/ansible b/bin/ansible index af669e099e..f8c72234c8 100755 --- a/bin/ansible +++ b/bin/ansible @@ -159,7 +159,7 @@ if __name__ == '__main__': if 'failed' in result or result.get('rc', 0) != 0: sys.exit(2) if results['dark']: - sys.exit(2) + sys.exit(3) except errors.AnsibleError, e: # Generic handler for ansible specific errors callbacks.display("ERROR: %s" % str(e), stderr=True, color='red') diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 818e50cf77..4e76aba21f 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -202,6 +202,7 @@ def main(args): return 0 failed_hosts = [] + unreachable_hosts = [] try: @@ -213,11 +214,15 @@ def main(args): for h in hosts: t = pb.stats.summarize(h) - if t['unreachable'] > 0 or t['failures'] > 0: + if t['failures'] > 0: failed_hosts.append(h) + if t['unreachable'] > 0: + unreachable_hosts.append(h) - if len(failed_hosts) > 0: - filename = pb.generate_retry_inventory(failed_hosts) + retries = failed_hosts + unreachable_hosts + + if len(retries) > 0: + filename = pb.generate_retry_inventory(retries) if filename: display(" to retry, use: --limit @%s\n" % filename) @@ -246,6 +251,8 @@ def main(args): print "" if len(failed_hosts) > 0: return 2 + if len(unreachable_hosts) > 0: + return 3 except errors.AnsibleError, e: display("ERROR: %s" % e, color='red')