mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-09 01:44:03 -07:00
issue #994: use HAS_BOTO to determine if import was successful: - removed import of sys module. - HAS_BOTO constant to check if import was successful. - trigger a failure when import fails. - removed unnecessary imports.
This commit is contained in:
parent
0a48d54c1c
commit
67f769d9a6
21 changed files with 121 additions and 74 deletions
|
@ -129,15 +129,17 @@ EXAMPLES = '''
|
|||
state: absent
|
||||
|
||||
'''
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
try:
|
||||
import boto
|
||||
import boto.ec2
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
print "failed=True msg='boto required for this module'"
|
||||
sys.exit(1)
|
||||
HAS_BOTO = False
|
||||
|
||||
|
||||
def create_image(module, ec2):
|
||||
"""
|
||||
|
@ -226,6 +228,7 @@ def deregister_image(module, ec2):
|
|||
module.exit_json(msg="AMI deregister/delete operation complete", changed=True)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = ec2_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
|
@ -242,6 +245,9 @@ def main():
|
|||
)
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
|
||||
if not HAS_BOTO:
|
||||
module.fail_json(msg='boto required for this module')
|
||||
|
||||
try:
|
||||
ec2 = ec2_connect(module)
|
||||
except Exception, e:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue