Don't raise or catch StandardError in amazon modules
This commit is contained in:
parent
5fbc5cb529
commit
5bd1bcaa2d
15 changed files with 164 additions and 176 deletions
|
@ -272,8 +272,7 @@ def main():
|
|||
|
||||
try:
|
||||
connection = connect_to_aws(boto.dynamodb2, region, **aws_connect_params)
|
||||
|
||||
except (NoAuthHandlerFound, StandardError), e:
|
||||
except (NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
state = module.params.get('state')
|
||||
|
|
|
@ -182,7 +182,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.ec2.elb, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -192,4 +192,5 @@ def main():
|
|||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -193,9 +193,6 @@ def create_eni(connection, module):
|
|||
instance_id = module.params.get("instance_id")
|
||||
if instance_id == 'None':
|
||||
instance_id = None
|
||||
do_detach = True
|
||||
else:
|
||||
do_detach = False
|
||||
device_index = module.params.get("device_index")
|
||||
subnet_id = module.params.get('subnet_id')
|
||||
private_ip_address = module.params.get('private_ip_address')
|
||||
|
@ -210,7 +207,7 @@ def create_eni(connection, module):
|
|||
if instance_id is not None:
|
||||
try:
|
||||
eni.attach(instance_id, device_index)
|
||||
except BotoServerError as ex:
|
||||
except BotoServerError:
|
||||
eni.delete()
|
||||
raise
|
||||
# Wait to allow creation / attachment to finish
|
||||
|
@ -234,8 +231,6 @@ def modify_eni(connection, module):
|
|||
else:
|
||||
do_detach = False
|
||||
device_index = module.params.get("device_index")
|
||||
subnet_id = module.params.get('subnet_id')
|
||||
private_ip_address = module.params.get('private_ip_address')
|
||||
description = module.params.get('description')
|
||||
security_groups = module.params.get('security_groups')
|
||||
force_detach = module.params.get("force_detach")
|
||||
|
@ -243,7 +238,6 @@ def modify_eni(connection, module):
|
|||
delete_on_termination = module.params.get("delete_on_termination")
|
||||
changed = False
|
||||
|
||||
|
||||
try:
|
||||
# Get the eni with the eni_id specified
|
||||
eni_result_set = connection.get_all_network_interfaces(eni_id)
|
||||
|
@ -374,7 +368,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -401,4 +395,5 @@ from ansible.module_utils.ec2 import *
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -123,7 +123,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
|
|
@ -154,7 +154,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -167,4 +167,3 @@ from ansible.module_utils.ec2 import *
|
|||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
|
|
@ -570,7 +570,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -597,4 +597,3 @@ from ansible.module_utils.ec2 import * # noqa
|
|||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
|
|
@ -249,14 +249,13 @@ def main():
|
|||
if not region:
|
||||
module.fail_json(msg='Region must be specified')
|
||||
|
||||
if region:
|
||||
try:
|
||||
vpc_conn = boto.vpc.connect_to_region(
|
||||
region,
|
||||
aws_access_key_id=aws_access_key,
|
||||
aws_secret_access_key=aws_secret_key
|
||||
)
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
vpc_id = module.params.get('vpc_id')
|
||||
tags = module.params.get('tags')
|
||||
|
@ -281,4 +280,3 @@ from ansible.module_utils.ec2 import * # noqa
|
|||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
|
|
@ -24,7 +24,8 @@ notes:
|
|||
description:
|
||||
- Creates or terminates ecs clusters.
|
||||
version_added: "2.0"
|
||||
requirements: [ json, time, boto, boto3 ]
|
||||
author: Mark Chance(@Java1Guy)
|
||||
requirements: [ boto, boto3 ]
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
|
@ -97,8 +98,9 @@ status:
|
|||
returned: ACTIVE
|
||||
type: string
|
||||
'''
|
||||
import time
|
||||
|
||||
try:
|
||||
import json, time
|
||||
import boto
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
|
@ -144,7 +146,7 @@ class EcsClusterManager:
|
|||
c = self.find_in_array(response['clusters'], cluster_name)
|
||||
if c:
|
||||
return c
|
||||
raise StandardError("Unknown problem describing cluster %s." % cluster_name)
|
||||
raise Exception("Unknown problem describing cluster %s." % cluster_name)
|
||||
|
||||
def create_cluster(self, clusterName = 'default'):
|
||||
response = self.ecs.create_cluster(clusterName=clusterName)
|
||||
|
@ -172,8 +174,6 @@ def main():
|
|||
if not HAS_BOTO3:
|
||||
module.fail_json(msg='boto3 is required.')
|
||||
|
||||
cluster_name = module.params['name']
|
||||
|
||||
cluster_mgr = EcsClusterManager(module)
|
||||
try:
|
||||
existing = cluster_mgr.describe_cluster(module.params['name'])
|
||||
|
|
|
@ -328,7 +328,6 @@ def destroy_lifecycle_rule(connection, module):
|
|||
else:
|
||||
lifecycle_obj.append(existing_rule)
|
||||
|
||||
|
||||
# Write lifecycle to bucket or, if there no rules left, delete lifecycle configuration
|
||||
try:
|
||||
if lifecycle_obj:
|
||||
|
@ -389,7 +388,7 @@ def main():
|
|||
# use this as fallback because connect_to_region seems to fail in boto + non 'classic' aws accounts in some cases
|
||||
if connection is None:
|
||||
connection = boto.connect_s3(**aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
expiration_date = module.params.get("expiration_date")
|
||||
|
|
|
@ -166,10 +166,9 @@ def main():
|
|||
# use this as fallback because connect_to_region seems to fail in boto + non 'classic' aws accounts in some cases
|
||||
if connection is None:
|
||||
connection = boto.connect_s3(**aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
|
||||
state = module.params.get("state")
|
||||
|
||||
if state == 'present':
|
||||
|
|
|
@ -220,7 +220,7 @@ def main():
|
|||
try:
|
||||
connection = connect_to_aws(boto.sqs, region, **aws_connect_params)
|
||||
|
||||
except (NoAuthHandlerFound, StandardError), e:
|
||||
except (NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -234,4 +234,5 @@ def main():
|
|||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -82,9 +82,6 @@ ec2_tag:
|
|||
|
||||
'''
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
try:
|
||||
import boto.sts
|
||||
from boto.exception import BotoServerError
|
||||
|
@ -136,7 +133,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.sts, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -151,4 +148,5 @@ def main():
|
|||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue