mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix amazon extras modules to compile under python3
This commit is contained in:
parent
46a1f73778
commit
3901fe72d3
31 changed files with 192 additions and 190 deletions
|
@ -101,6 +101,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import connect_to_aws, ec2_argument_spec, get_ec2_creds
|
||||
|
||||
|
||||
class CloudTrailManager:
|
||||
"""Handles cloudtrail configuration"""
|
||||
|
||||
|
@ -112,7 +116,7 @@ class CloudTrailManager:
|
|||
|
||||
try:
|
||||
self.conn = connect_to_aws(boto.cloudtrail, self.region, **self.aws_connect_params)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
self.module.fail_json(msg=str(e))
|
||||
|
||||
def view_status(self, name):
|
||||
|
@ -222,8 +226,6 @@ def main():
|
|||
|
||||
module.exit_json(**results)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -133,6 +133,8 @@ table_status:
|
|||
sample: ACTIVE
|
||||
'''
|
||||
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import boto
|
||||
import boto.dynamodb2
|
||||
|
@ -152,6 +154,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
DYNAMO_TYPE_DEFAULT = 'STRING'
|
||||
INDEX_REQUIRED_OPTIONS = ['name', 'type', 'hash_key_name']
|
||||
INDEX_OPTIONS = INDEX_REQUIRED_OPTIONS + ['hash_key_type', 'range_key_name', 'range_key_type', 'includes', 'read_capacity', 'write_capacity']
|
||||
|
@ -244,7 +250,7 @@ def dynamo_table_exists(table):
|
|||
table.describe()
|
||||
return True
|
||||
|
||||
except JSONResponseError, e:
|
||||
except JSONResponseError as e:
|
||||
if e.message and e.message.startswith('Requested resource not found'):
|
||||
return False
|
||||
else:
|
||||
|
@ -281,7 +287,7 @@ def update_dynamo_table(table, throughput=None, check_mode=False, global_indexes
|
|||
# todo: remove try once boto has https://github.com/boto/boto/pull/3447 fixed
|
||||
try:
|
||||
global_indexes_changed = table.update_global_secondary_index(global_indexes=index_throughput_changes) or global_indexes_changed
|
||||
except ValidationException as e:
|
||||
except ValidationException:
|
||||
pass
|
||||
else:
|
||||
global_indexes_changed = True
|
||||
|
@ -398,7 +404,7 @@ def main():
|
|||
|
||||
try:
|
||||
connection = connect_to_aws(boto.dynamodb2, region, **aws_connect_params)
|
||||
except (NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -408,9 +414,5 @@ def main():
|
|||
delete_dynamo_table(connection, module)
|
||||
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -127,6 +127,8 @@ EXAMPLES = '''
|
|||
kms_key_id: arn:aws:kms:us-east-1:XXXXXXXXXXXX:key/746de6ea-50a4-4bcb-8fbc-e3b29f2d367b
|
||||
'''
|
||||
|
||||
import time
|
||||
|
||||
try:
|
||||
import boto
|
||||
import boto.ec2
|
||||
|
@ -134,6 +136,9 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import ec2_argument_spec, ec2_connect, get_aws_connection_info
|
||||
|
||||
|
||||
def copy_image(module, ec2):
|
||||
"""
|
||||
|
@ -163,7 +168,7 @@ def copy_image(module, ec2):
|
|||
}
|
||||
|
||||
image_id = ec2.copy_image(**params).image_id
|
||||
except boto.exception.BotoServerError, e:
|
||||
except boto.exception.BotoServerError as e:
|
||||
module.fail_json(msg="%s: %s" % (e.error_code, e.error_message))
|
||||
|
||||
img = wait_until_image_is_recognized(module, ec2, wait_timeout, image_id, wait)
|
||||
|
@ -201,7 +206,7 @@ def wait_until_image_is_recognized(module, ec2, wait_timeout, image_id, wait):
|
|||
for i in range(wait_timeout):
|
||||
try:
|
||||
return ec2.get_image(image_id)
|
||||
except boto.exception.EC2ResponseError, e:
|
||||
except boto.exception.EC2ResponseError as e:
|
||||
# This exception we expect initially right after registering the copy with EC2 API
|
||||
if 'InvalidAMIID.NotFound' in e.error_code and wait:
|
||||
time.sleep(1)
|
||||
|
@ -234,12 +239,12 @@ def main():
|
|||
|
||||
try:
|
||||
ec2 = ec2_connect(module)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
try:
|
||||
region, ec2_url, boto_params = get_aws_connection_info(module)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
if not region:
|
||||
|
@ -248,9 +253,6 @@ def main():
|
|||
copy_image(module, ec2)
|
||||
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -120,6 +120,11 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import (boto3_conn, camel_dict_to_snake_dict,
|
||||
ec2_argument_spec, get_aws_connection_info)
|
||||
|
||||
|
||||
class Ec2CustomerGatewayManager:
|
||||
|
||||
def __init__(self, module):
|
||||
|
@ -130,7 +135,7 @@ class Ec2CustomerGatewayManager:
|
|||
if not region:
|
||||
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
|
||||
self.ec2 = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except ClientError, e:
|
||||
except ClientError as e:
|
||||
module.fail_json(msg=e.message)
|
||||
|
||||
def ensure_cgw_absent(self, gw_id):
|
||||
|
@ -211,8 +216,6 @@ def main():
|
|||
|
||||
gw_mgr = Ec2CustomerGatewayManager(module)
|
||||
|
||||
bgp_asn = module.params.get('bgp_asn')
|
||||
ip_address = module.params.get('ip_address')
|
||||
name = module.params.get('name')
|
||||
|
||||
existing = gw_mgr.describe_gateways(module.params['ip_address'])
|
||||
|
@ -259,9 +262,6 @@ def main():
|
|||
pretty_results = camel_dict_to_snake_dict(results)
|
||||
module.exit_json(**pretty_results)
|
||||
|
||||
# import module methods
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -241,6 +241,12 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import (AnsibleAWSError, connect_to_aws,
|
||||
ec2_argument_spec, get_aws_connection_info,
|
||||
get_ec2_security_group_ids_from_names)
|
||||
|
||||
|
||||
def get_eni_info(interface):
|
||||
|
||||
# Private addresses
|
||||
|
@ -539,7 +545,7 @@ def main():
|
|||
try:
|
||||
connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
|
||||
vpc_connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -561,8 +567,6 @@ def main():
|
|||
elif state == 'absent':
|
||||
delete_eni(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -60,6 +60,12 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import (AnsibleAWSError,
|
||||
ansible_dict_to_boto3_filter_list, boto3_conn,
|
||||
boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict,
|
||||
connect_to_aws, ec2_argument_spec, get_aws_connection_info)
|
||||
|
||||
|
||||
def list_ec2_snapshots_boto3(connection, module):
|
||||
|
||||
|
@ -172,15 +178,13 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
list_eni(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -65,6 +65,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def get_instance_info(instance):
|
||||
|
||||
# Get groups
|
||||
|
@ -171,16 +175,13 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
list_ec2_instances(connection, module)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -163,6 +163,11 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import (ansible_dict_to_boto3_filter_list,
|
||||
boto3_conn, boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict,
|
||||
ec2_argument_spec, get_aws_connection_info)
|
||||
|
||||
|
||||
def list_ec2_snapshots(connection, module):
|
||||
|
||||
|
@ -173,7 +178,7 @@ def list_ec2_snapshots(connection, module):
|
|||
|
||||
try:
|
||||
snapshots = connection.describe_snapshots(SnapshotIds=snapshot_ids, OwnerIds=owner_ids, RestorableByUserIds=restorable_by_user_ids, Filters=filters)
|
||||
except ClientError, e:
|
||||
except ClientError as e:
|
||||
module.fail_json(msg=e.message)
|
||||
|
||||
# Turn the boto3 result in to ansible_friendly_snaked_names
|
||||
|
@ -219,8 +224,6 @@ def main():
|
|||
|
||||
list_ec2_snapshots(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -66,6 +66,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def get_volume_info(volume):
|
||||
|
||||
attachment = volume.attach_data
|
||||
|
@ -125,15 +129,13 @@ 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, StandardError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
list_ec2_volumes(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -54,8 +54,6 @@ register: igw
|
|||
|
||||
'''
|
||||
|
||||
import sys # noqa
|
||||
|
||||
try:
|
||||
import boto.ec2
|
||||
import boto.vpc
|
||||
|
@ -66,6 +64,9 @@ except ImportError:
|
|||
if __name__ != '__main__':
|
||||
raise
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class AnsibleIGWException(Exception):
|
||||
pass
|
||||
|
@ -138,7 +139,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -156,8 +157,6 @@ def main():
|
|||
|
||||
module.exit_json(**result)
|
||||
|
||||
from ansible.module_utils.basic import * # noqa
|
||||
from ansible.module_utils.ec2 import * # noqa
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -122,13 +122,15 @@ task:
|
|||
'''
|
||||
|
||||
try:
|
||||
import json
|
||||
import botocore
|
||||
import boto3
|
||||
HAS_BOTO3 = True
|
||||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
# Common fields for the default rule that is contained within every VPC NACL.
|
||||
DEFAULT_RULE_FIELDS = {
|
||||
|
@ -179,7 +181,6 @@ def subnets_added(nacl_id, subnets, client, module):
|
|||
|
||||
def subnets_changed(nacl, client, module):
|
||||
changed = False
|
||||
response = {}
|
||||
vpc_id = module.params.get('vpc_id')
|
||||
nacl_id = nacl['NetworkAcls'][0]['NetworkAclId']
|
||||
subnets = subnets_to_associate(nacl, client, module)
|
||||
|
@ -528,9 +529,9 @@ def main():
|
|||
try:
|
||||
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
|
||||
client = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except botocore.exceptions.NoCredentialsError, e:
|
||||
module.fail_json(msg="Can't authorize connection - "+str(e))
|
||||
|
||||
except botocore.exceptions.NoCredentialsError as e:
|
||||
module.fail_json(msg="Can't authorize connection - %s" % str(e))
|
||||
|
||||
invocations = {
|
||||
"present": setup_network_acl,
|
||||
"absent": remove_network_acl
|
||||
|
@ -538,9 +539,6 @@ def main():
|
|||
(changed, results) = invocations[state](client, module)
|
||||
module.exit_json(changed=changed, nacl_id=results)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -58,6 +58,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def get_vpc_info(vpc):
|
||||
|
||||
try:
|
||||
|
@ -111,15 +115,13 @@ 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, StandardError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
list_ec2_vpcs(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -106,8 +106,6 @@ EXAMPLES = '''
|
|||
|
||||
'''
|
||||
|
||||
|
||||
import sys # noqa
|
||||
import re
|
||||
|
||||
try:
|
||||
|
@ -120,6 +118,9 @@ except ImportError:
|
|||
if __name__ != '__main__':
|
||||
raise
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class AnsibleRouteTableException(Exception):
|
||||
pass
|
||||
|
@ -178,7 +179,7 @@ def find_subnets(vpc_conn, vpc_id, identified_subnets):
|
|||
for cidr in subnet_cidrs:
|
||||
if not any(s.cidr_block == cidr for s in subnets_by_cidr):
|
||||
raise AnsibleSubnetSearchException(
|
||||
'Subnet CIDR "{0}" does not exist'.format(subnet_cidr))
|
||||
'Subnet CIDR "{0}" does not exist'.format(cidr))
|
||||
|
||||
subnets_by_name = []
|
||||
if subnet_names:
|
||||
|
@ -604,7 +605,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -626,8 +627,6 @@ def main():
|
|||
|
||||
module.exit_json(**result)
|
||||
|
||||
from ansible.module_utils.basic import * # noqa
|
||||
from ansible.module_utils.ec2 import * # noqa
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -67,6 +67,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def get_route_table_info(route_table):
|
||||
|
||||
# Add any routes to array
|
||||
|
@ -116,15 +120,13 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
list_ec2_vpc_route_tables(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -73,7 +73,6 @@ EXAMPLES = '''
|
|||
|
||||
'''
|
||||
|
||||
import sys # noqa
|
||||
import time
|
||||
|
||||
try:
|
||||
|
@ -86,6 +85,9 @@ except ImportError:
|
|||
if __name__ != '__main__':
|
||||
raise
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class AnsibleVPCSubnetException(Exception):
|
||||
pass
|
||||
|
@ -252,7 +254,7 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
@ -275,8 +277,6 @@ def main():
|
|||
|
||||
module.exit_json(**result)
|
||||
|
||||
from ansible.module_utils.basic import * # noqa
|
||||
from ansible.module_utils.ec2 import * # noqa
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -82,6 +82,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def get_subnet_info(subnet):
|
||||
|
||||
subnet_info = { 'id': subnet.id,
|
||||
|
@ -131,15 +135,13 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
list_ec2_vpc_subnets(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -115,6 +115,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class EcsClusterManager:
|
||||
"""Handles ECS Clusters"""
|
||||
|
||||
|
@ -127,8 +131,8 @@ class EcsClusterManager:
|
|||
if not region:
|
||||
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
|
||||
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
self.module.fail_json(msg="Can't authorize connection - "+str(e))
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
self.module.fail_json(msg="Can't authorize connection - %s" % str(e))
|
||||
|
||||
def find_in_array(self, array_of_clusters, cluster_name, field_name='clusterArn'):
|
||||
for c in array_of_clusters:
|
||||
|
@ -180,7 +184,7 @@ def main():
|
|||
cluster_mgr = EcsClusterManager(module)
|
||||
try:
|
||||
existing = cluster_mgr.describe_cluster(module.params['name'])
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Exception describing cluster '"+module.params['name']+"': "+str(e))
|
||||
|
||||
results = dict(changed=False)
|
||||
|
@ -230,9 +234,6 @@ def main():
|
|||
|
||||
module.exit_json(**results)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -175,6 +175,8 @@ ansible_facts:
|
|||
returned: when service existed and was deleted
|
||||
type: complex
|
||||
'''
|
||||
import time
|
||||
|
||||
try:
|
||||
import boto
|
||||
import botocore
|
||||
|
@ -188,6 +190,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class EcsServiceManager:
|
||||
"""Handles ECS Services"""
|
||||
|
||||
|
@ -200,8 +206,8 @@ class EcsServiceManager:
|
|||
if not region:
|
||||
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
|
||||
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
self.module.fail_json(msg="Can't authorize connection - "+str(e))
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
self.module.fail_json(msg="Can't authorize connection - %s" % str(e))
|
||||
|
||||
# def list_clusters(self):
|
||||
# return self.client.list_clusters()
|
||||
|
@ -321,7 +327,7 @@ def main():
|
|||
service_mgr = EcsServiceManager(module)
|
||||
try:
|
||||
existing = service_mgr.describe_service(module.params['cluster'], module.params['name'])
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Exception describing service '"+module.params['name']+"' in cluster '"+module.params['cluster']+"': "+str(e))
|
||||
|
||||
results = dict(changed=False )
|
||||
|
@ -392,7 +398,7 @@ def main():
|
|||
module.params['name'],
|
||||
module.params['cluster']
|
||||
)
|
||||
except botocore.exceptions.ClientError, e:
|
||||
except botocore.exceptions.ClientError as e:
|
||||
module.fail_json(msg=e.message)
|
||||
results['changed'] = True
|
||||
|
||||
|
@ -418,9 +424,6 @@ def main():
|
|||
|
||||
module.exit_json(**results)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -139,6 +139,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class EcsServiceManager:
|
||||
"""Handles ECS Services"""
|
||||
|
||||
|
@ -151,8 +155,8 @@ class EcsServiceManager:
|
|||
if not region:
|
||||
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
|
||||
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
self.module.fail_json(msg="Can't authorize connection - "+str(e))
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
self.module.fail_json(msg="Can't authorize connection - %s" % str(e))
|
||||
|
||||
# def list_clusters(self):
|
||||
# return self.client.list_clusters()
|
||||
|
@ -227,10 +231,6 @@ def main():
|
|||
ecs_facts_result = dict(changed=False, ansible_facts=ecs_facts)
|
||||
module.exit_json(**ecs_facts_result)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.urls import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -165,6 +165,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class EcsExecManager:
|
||||
"""Handles ECS Tasks"""
|
||||
|
||||
|
@ -176,8 +180,8 @@ class EcsExecManager:
|
|||
if not region:
|
||||
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
|
||||
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
module.fail_json(msg="Can't authorize connection - "+str(e))
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
module.fail_json(msg="Can't authorize connection - %s " % str(e))
|
||||
|
||||
def list_tasks(self, cluster_name, service_name, status):
|
||||
response = self.ecs.list_tasks(
|
||||
|
@ -316,9 +320,6 @@ def main():
|
|||
|
||||
module.exit_json(**results)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -107,6 +107,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class EcsTaskManager:
|
||||
"""Handles ECS Tasks"""
|
||||
|
||||
|
@ -118,8 +122,8 @@ class EcsTaskManager:
|
|||
if not region:
|
||||
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
|
||||
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
module.fail_json(msg="Can't authorize connection - "+str(e))
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
module.fail_json(msg="Can't authorize connection - " % str(e))
|
||||
|
||||
def describe_task(self, task_name):
|
||||
try:
|
||||
|
@ -212,9 +216,6 @@ def main():
|
|||
|
||||
module.exit_json(**results)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -172,6 +172,9 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def get_hosted_zone(client, module):
|
||||
params = dict()
|
||||
|
@ -413,8 +416,8 @@ def main():
|
|||
try:
|
||||
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
|
||||
route53 = boto3_conn(module, conn_type='client', resource='route53', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
module.fail_json(msg="Can't authorize connection - "+str(e))
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
module.fail_json(msg="Can't authorize connection - %s " % str(e))
|
||||
|
||||
invocations = {
|
||||
'change': change_details,
|
||||
|
@ -428,9 +431,6 @@ def main():
|
|||
|
||||
module.exit_json(**results)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -123,7 +123,6 @@ EXAMPLES = '''
|
|||
|
||||
'''
|
||||
|
||||
import time
|
||||
import uuid
|
||||
|
||||
try:
|
||||
|
@ -136,6 +135,11 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
# Things that can't get changed:
|
||||
# protocol
|
||||
# ip_address or domain
|
||||
|
@ -316,7 +320,7 @@ def main():
|
|||
# connect to the route53 endpoint
|
||||
try:
|
||||
conn = Route53Connection(**aws_connect_kwargs)
|
||||
except boto.exception.BotoServerError, e:
|
||||
except boto.exception.BotoServerError as e:
|
||||
module.fail_json(msg = e.error_message)
|
||||
|
||||
changed = False
|
||||
|
@ -349,8 +353,6 @@ def main():
|
|||
|
||||
module.exit_json(changed=changed, health_check=dict(id=check_id), action=action)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -106,8 +106,6 @@ zone_id:
|
|||
sample: "Z6JQG9820BEFMW"
|
||||
'''
|
||||
|
||||
import time
|
||||
|
||||
try:
|
||||
import boto
|
||||
import boto.ec2
|
||||
|
@ -118,6 +116,9 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = ec2_argument_spec()
|
||||
|
@ -148,7 +149,7 @@ def main():
|
|||
# connect to the route53 endpoint
|
||||
try:
|
||||
conn = Route53Connection(**aws_connect_kwargs)
|
||||
except boto.exception.BotoServerError, e:
|
||||
except boto.exception.BotoServerError as e:
|
||||
module.fail_json(msg=e.error_message)
|
||||
|
||||
results = conn.get_all_hosted_zones()
|
||||
|
@ -216,7 +217,5 @@ def main():
|
|||
elif state == 'absent':
|
||||
module.exit_json(changed=False)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -163,6 +163,9 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
def create_lifecycle_rule(connection, module):
|
||||
|
||||
name = module.params.get("name")
|
||||
|
@ -178,13 +181,13 @@ def create_lifecycle_rule(connection, module):
|
|||
|
||||
try:
|
||||
bucket = connection.get_bucket(name)
|
||||
except S3ResponseError, e:
|
||||
except S3ResponseError as e:
|
||||
module.fail_json(msg=e.message)
|
||||
|
||||
# Get the bucket's current lifecycle rules
|
||||
try:
|
||||
current_lifecycle_obj = bucket.get_lifecycle_config()
|
||||
except S3ResponseError, e:
|
||||
except S3ResponseError as e:
|
||||
if e.error_code == "NoSuchLifecycleConfiguration":
|
||||
current_lifecycle_obj = Lifecycle()
|
||||
else:
|
||||
|
@ -247,7 +250,7 @@ def create_lifecycle_rule(connection, module):
|
|||
# Write lifecycle to bucket
|
||||
try:
|
||||
bucket.configure_lifecycle(lifecycle_obj)
|
||||
except S3ResponseError, e:
|
||||
except S3ResponseError as e:
|
||||
module.fail_json(msg=e.message)
|
||||
|
||||
module.exit_json(changed=changed)
|
||||
|
@ -309,13 +312,13 @@ def destroy_lifecycle_rule(connection, module):
|
|||
|
||||
try:
|
||||
bucket = connection.get_bucket(name)
|
||||
except S3ResponseError, e:
|
||||
except S3ResponseError as e:
|
||||
module.fail_json(msg=e.message)
|
||||
|
||||
# Get the bucket's current lifecycle rules
|
||||
try:
|
||||
current_lifecycle_obj = bucket.get_lifecycle_config()
|
||||
except S3ResponseError, e:
|
||||
except S3ResponseError as e:
|
||||
if e.error_code == "NoSuchLifecycleConfiguration":
|
||||
module.exit_json(changed=changed)
|
||||
else:
|
||||
|
@ -347,7 +350,7 @@ def destroy_lifecycle_rule(connection, module):
|
|||
bucket.configure_lifecycle(lifecycle_obj)
|
||||
else:
|
||||
bucket.delete_lifecycle_configuration()
|
||||
except BotoServerError, e:
|
||||
except BotoServerError as e:
|
||||
module.fail_json(msg=e.message)
|
||||
|
||||
module.exit_json(changed=changed)
|
||||
|
@ -401,7 +404,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, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
expiration_date = module.params.get("expiration_date")
|
||||
|
@ -413,13 +416,13 @@ def main():
|
|||
if expiration_date is not None:
|
||||
try:
|
||||
datetime.datetime.strptime(expiration_date, "%Y-%m-%dT%H:%M:%S.000Z")
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
module.fail_json(msg="expiration_date is not a valid ISO-8601 format. The time must be midnight and a timezone of GMT must be included")
|
||||
|
||||
if transition_date is not None:
|
||||
try:
|
||||
datetime.datetime.strptime(transition_date, "%Y-%m-%dT%H:%M:%S.000Z")
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
module.fail_json(msg="expiration_date is not a valid ISO-8601 format. The time must be midnight and a timezone of GMT must be included")
|
||||
|
||||
boto_required_version = (2,40,0)
|
||||
|
@ -431,8 +434,6 @@ def main():
|
|||
elif state == 'absent':
|
||||
destroy_lifecycle_rule(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -76,6 +76,9 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def compare_bucket_logging(bucket, target_bucket, target_prefix):
|
||||
|
||||
|
@ -166,7 +169,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, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
state = module.params.get("state")
|
||||
|
@ -176,8 +179,6 @@ def main():
|
|||
elif state == 'absent':
|
||||
disable_bucket_logging(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -122,7 +122,6 @@ sns_topic:
|
|||
attributes_set: []
|
||||
'''
|
||||
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import re
|
||||
|
@ -134,6 +133,9 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
class SnsTopicManager(object):
|
||||
""" Handles SNS Topic creation and destruction """
|
||||
|
@ -176,7 +178,7 @@ class SnsTopicManager(object):
|
|||
try:
|
||||
return connect_to_aws(boto.sns, self.region,
|
||||
**self.aws_connect_params)
|
||||
except BotoServerError, err:
|
||||
except BotoServerError as err:
|
||||
self.module.fail_json(msg=err.message)
|
||||
|
||||
def _get_all_topics(self):
|
||||
|
@ -185,8 +187,8 @@ class SnsTopicManager(object):
|
|||
while True:
|
||||
try:
|
||||
response = self.connection.get_all_topics(next_token)
|
||||
except BotoServerError, err:
|
||||
module.fail_json(msg=err.message)
|
||||
except BotoServerError as err:
|
||||
self.module.fail_json(msg=err.message)
|
||||
topics.extend(response['ListTopicsResponse']['ListTopicsResult']['Topics'])
|
||||
next_token = response['ListTopicsResponse']['ListTopicsResult']['NextToken']
|
||||
if not next_token:
|
||||
|
@ -400,8 +402,5 @@ def main():
|
|||
module.exit_json(**sns_facts)
|
||||
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -103,6 +103,9 @@ EXAMPLES = '''
|
|||
state: absent
|
||||
'''
|
||||
|
||||
import json
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import boto.sqs
|
||||
from boto.exception import BotoServerError, NoAuthHandlerFound
|
||||
|
@ -111,6 +114,9 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def create_or_update_sqs_queue(connection, module):
|
||||
queue_name = module.params.get('name')
|
||||
|
@ -255,7 +261,7 @@ def main():
|
|||
try:
|
||||
connection = connect_to_aws(boto.sqs, region, **aws_connect_params)
|
||||
|
||||
except (NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -265,9 +271,5 @@ def main():
|
|||
delete_sqs_queue(connection, module)
|
||||
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -89,6 +89,9 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import AnsibleAWSError, connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def assume_role_policy(connection, module):
|
||||
|
||||
|
@ -104,7 +107,7 @@ def assume_role_policy(connection, module):
|
|||
try:
|
||||
assumed_role = connection.assume_role(role_arn, role_session_name, policy, duration_seconds, external_id, mfa_serial_number, mfa_token)
|
||||
changed = True
|
||||
except BotoServerError, e:
|
||||
except BotoServerError as e:
|
||||
module.fail_json(msg=e)
|
||||
|
||||
module.exit_json(changed=changed, sts_creds=assumed_role.credentials.__dict__, sts_user=assumed_role.user.__dict__)
|
||||
|
@ -133,20 +136,16 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.sts, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
try:
|
||||
assume_role_policy(connection, module)
|
||||
except BotoServerError, e:
|
||||
except BotoServerError as e:
|
||||
module.fail_json(msg=e)
|
||||
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -46,6 +46,7 @@ extends_documentation_fragment:
|
|||
requirements:
|
||||
- boto3
|
||||
- botocore
|
||||
- python >= 2.6
|
||||
'''
|
||||
|
||||
RETURN = """
|
||||
|
@ -92,6 +93,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||
|
||||
|
||||
def normalize_credentials(credentials):
|
||||
access_key = credentials.get('AccessKeyId', None)
|
||||
secret_key = credentials.get('SecretAccessKey', None)
|
||||
|
@ -121,7 +126,7 @@ def get_session_token(connection, module):
|
|||
try:
|
||||
response = connection.get_session_token(**args)
|
||||
changed = True
|
||||
except ClientError, e:
|
||||
except ClientError as e:
|
||||
module.fail_json(msg=e)
|
||||
|
||||
credentials = normalize_credentials(response.get('Credentials', {}))
|
||||
|
@ -151,9 +156,5 @@ def main():
|
|||
get_session_token(connection, module)
|
||||
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -1,33 +1,3 @@
|
|||
/cloud/amazon/cloudtrail.py
|
||||
/cloud/amazon/dynamodb_table.py
|
||||
/cloud/amazon/ec2_ami_copy.py
|
||||
/cloud/amazon/ec2_customer_gateway.py
|
||||
/cloud/amazon/ec2_eni.py
|
||||
/cloud/amazon/ec2_eni_facts.py
|
||||
/cloud/amazon/ec2_remote_facts.py
|
||||
/cloud/amazon/ec2_snapshot_facts.py
|
||||
/cloud/amazon/ec2_vol_facts.py
|
||||
/cloud/amazon/ec2_vpc_igw.py
|
||||
/cloud/amazon/ec2_vpc_nacl.py
|
||||
/cloud/amazon/ec2_vpc_net_facts.py
|
||||
/cloud/amazon/ec2_vpc_route_table.py
|
||||
/cloud/amazon/ec2_vpc_route_table_facts.py
|
||||
/cloud/amazon/ec2_vpc_subnet.py
|
||||
/cloud/amazon/ec2_vpc_subnet_facts.py
|
||||
/cloud/amazon/ecs_cluster.py
|
||||
/cloud/amazon/ecs_service.py
|
||||
/cloud/amazon/ecs_service_facts.py
|
||||
/cloud/amazon/ecs_task.py
|
||||
/cloud/amazon/ecs_taskdefinition.py
|
||||
/cloud/amazon/route53_facts.py
|
||||
/cloud/amazon/route53_health_check.py
|
||||
/cloud/amazon/route53_zone.py
|
||||
/cloud/amazon/s3_lifecycle.py
|
||||
/cloud/amazon/s3_logging.py
|
||||
/cloud/amazon/sns_topic.py
|
||||
/cloud/amazon/sqs_queue.py
|
||||
/cloud/amazon/sts_assume_role.py
|
||||
/cloud/amazon/sts_session_token.py
|
||||
/cloud/misc/virt_net.py
|
||||
/cloud/misc/virt_pool.py
|
||||
/cloud/profitbricks/profitbricks.py
|
||||
|
|
Loading…
Add table
Reference in a new issue