From f7d2f769768509519b632407a674e2b50ca4fc50 Mon Sep 17 00:00:00 2001 From: Niall Donegan Date: Wed, 15 Apr 2015 17:07:18 +0100 Subject: [PATCH] Handle missing module with fail_json --- lib/ansible/modules/extras/network/dnsimple.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/extras/network/dnsimple.py b/lib/ansible/modules/extras/network/dnsimple.py index 4e6ae4ec57e..9aa52172f19 100755 --- a/lib/ansible/modules/extras/network/dnsimple.py +++ b/lib/ansible/modules/extras/network/dnsimple.py @@ -130,13 +130,12 @@ EXAMPLES = ''' ''' import os -from sys import exit try: from dnsimple import DNSimple from dnsimple.dnsimple import DNSimpleException + HAS_DNSIMPLE = True except ImportError: - print "failed=True msg='dnsimple required for this module'" - exit(1) + HAS_DNSIMPLE = False def main(): module = AnsibleModule( @@ -159,6 +158,9 @@ def main(): supports_check_mode = True, ) + if not HAS_DNSIMPLE: + module.fail_json("dnsimple required for this module") + account_email = module.params.get('account_email') account_api_token = module.params.get('account_api_token') domain = module.params.get('domain')