From b4ad53224882fc18d332f9c181ebec8997ca3122 Mon Sep 17 00:00:00 2001 From: Niall Donegan Date: Wed, 15 Apr 2015 16:15:31 +0100 Subject: [PATCH 1/2] sys.exit used, but not imported. --- network/dnsimple.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/network/dnsimple.py b/network/dnsimple.py index 363a2ca24c1..4e6ae4ec57e 100755 --- a/network/dnsimple.py +++ b/network/dnsimple.py @@ -32,7 +32,7 @@ options: description: - Account API token. See I(account_email) for info. required: false - default: null + default: null domain: description: @@ -67,7 +67,7 @@ options: default: 3600 (one hour) value: - description: + description: - Record value - "Must be specified when trying to ensure a record exists" required: false @@ -130,12 +130,13 @@ EXAMPLES = ''' ''' import os +from sys import exit try: from dnsimple import DNSimple from dnsimple.dnsimple import DNSimpleException except ImportError: print "failed=True msg='dnsimple required for this module'" - sys.exit(1) + exit(1) def main(): module = AnsibleModule( @@ -148,7 +149,7 @@ def main(): type = dict(required=False, choices=['A', 'ALIAS', 'CNAME', 'MX', 'SPF', 'URL', 'TXT', 'NS', 'SRV', 'NAPTR', 'PTR', 'AAAA', 'SSHFP', 'HINFO', 'POOL']), ttl = dict(required=False, default=3600, type='int'), value = dict(required=False), - priority = dict(required=False, type='int'), + priority = dict(required=False, type='int'), state = dict(required=False, choices=['present', 'absent']), solo = dict(required=False, type='bool'), ), From b125d2685a0619435530a3267ae800ff7dcf6ebc Mon Sep 17 00:00:00 2001 From: Niall Donegan Date: Wed, 15 Apr 2015 17:07:18 +0100 Subject: [PATCH 2/2] Handle missing module with fail_json --- network/dnsimple.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/network/dnsimple.py b/network/dnsimple.py index 4e6ae4ec57e..9aa52172f19 100755 --- a/network/dnsimple.py +++ b/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')