Changed to use "connect_to_aws" method
This commit is contained in:
parent
4f2cd7cb6e
commit
3527aec2c5
1 changed files with 26 additions and 28 deletions
|
@ -20,7 +20,7 @@ short_description: Manage route tables for AWS virtual private clouds
|
||||||
description:
|
description:
|
||||||
- Manage route tables for AWS virtual private clouds
|
- Manage route tables for AWS virtual private clouds
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
author: Robert Estelle, @erydo
|
author: Robert Estelle (@erydo)
|
||||||
options:
|
options:
|
||||||
vpc_id:
|
vpc_id:
|
||||||
description:
|
description:
|
||||||
|
@ -470,34 +470,32 @@ def ensure_route_table_present(vpc_conn, vpc_id, route_table_id, resource_tags,
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ec2_argument_spec()
|
argument_spec = ec2_argument_spec()
|
||||||
argument_spec.update({
|
argument_spec.update(
|
||||||
'vpc_id': {'required': True},
|
dict(
|
||||||
'route_table_id': {'required': False},
|
vpc_id = dict(default=None, required=True),
|
||||||
'propagating_vgw_ids': {'type': 'list', 'required': False},
|
route_table_id = dict(default=None, required=False),
|
||||||
'resource_tags': {'type': 'dict', 'required': False},
|
propagating_vgw_ids = dict(default=None, required=False, type='list'),
|
||||||
'routes': {'type': 'list', 'required': False},
|
resource_tags = dict(default=None, required=False, type='dict'),
|
||||||
'subnets': {'type': 'list', 'required': False},
|
routes = dict(default=None, required=False, type='list'),
|
||||||
'state': {'choices': ['present', 'absent'], 'default': 'present'},
|
subnets = dict(default=None, required=False, type='list'),
|
||||||
})
|
state = dict(default='present', choices=['present', 'absent'])
|
||||||
module = AnsibleModule(
|
)
|
||||||
argument_spec=argument_spec,
|
|
||||||
supports_check_mode=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||||
|
|
||||||
if not HAS_BOTO:
|
if not HAS_BOTO:
|
||||||
module.fail_json(msg='boto is required for this module')
|
module.fail_json(msg='boto is required for this module')
|
||||||
|
|
||||||
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module)
|
region, ec2_url, aws_connect_params = get_aws_connection_info(module)
|
||||||
if not region:
|
|
||||||
module.fail_json(msg='Region must be specified')
|
if region:
|
||||||
|
try:
|
||||||
try:
|
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||||
vpc_conn = boto.vpc.connect_to_region(
|
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||||
region,
|
module.fail_json(msg=str(e))
|
||||||
aws_access_key_id=aws_access_key,
|
else:
|
||||||
aws_secret_access_key=aws_secret_key
|
module.fail_json(msg="region must be specified")
|
||||||
)
|
|
||||||
except boto.exception.NoAuthHandlerFound as e:
|
|
||||||
module.fail_json(msg=str(e))
|
|
||||||
|
|
||||||
vpc_id = module.params.get('vpc_id')
|
vpc_id = module.params.get('vpc_id')
|
||||||
route_table_id = module.params.get('route_table_id')
|
route_table_id = module.params.get('route_table_id')
|
||||||
|
@ -510,7 +508,7 @@ def main():
|
||||||
|
|
||||||
if 'gateway_id' in route_spec and route_spec['gateway_id'] and \
|
if 'gateway_id' in route_spec and route_spec['gateway_id'] and \
|
||||||
route_spec['gateway_id'].lower() == 'igw':
|
route_spec['gateway_id'].lower() == 'igw':
|
||||||
igw = find_igw(vpc_conn, vpc_id)
|
igw = find_igw(connection, vpc_id)
|
||||||
route_spec['gateway_id'] = igw
|
route_spec['gateway_id'] = igw
|
||||||
|
|
||||||
subnets = module.params.get('subnets')
|
subnets = module.params.get('subnets')
|
||||||
|
@ -519,12 +517,12 @@ def main():
|
||||||
try:
|
try:
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
result = ensure_route_table_present(
|
result = ensure_route_table_present(
|
||||||
vpc_conn, vpc_id, route_table_id, resource_tags,
|
connection, vpc_id, route_table_id, resource_tags,
|
||||||
routes, subnets, propagating_vgw_ids, module.check_mode
|
routes, subnets, propagating_vgw_ids, module.check_mode
|
||||||
)
|
)
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
result = ensure_route_table_absent(
|
result = ensure_route_table_absent(
|
||||||
vpc_conn, vpc_id, route_table_id, resource_tags,
|
connection, vpc_id, route_table_id, resource_tags,
|
||||||
module.check_mode
|
module.check_mode
|
||||||
)
|
)
|
||||||
except AnsibleRouteTableException as e:
|
except AnsibleRouteTableException as e:
|
||||||
|
|
Loading…
Reference in a new issue