Changed to use "connect_to_aws" method

reviewable/pr18780/r1
whiter 11 years ago
parent 65f98d53af
commit c93cf8c054

@ -20,7 +20,7 @@ short_description: Manage subnets in AWS virtual private clouds
description: description:
- Manage subnets in AWS virtual private clouds - Manage subnets in 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:
@ -36,14 +36,16 @@ options:
description: description:
- The CIDR block for the subnet. E.g. 10.0.0.0/16. Only required when state=present." - The CIDR block for the subnet. E.g. 10.0.0.0/16. Only required when state=present."
required: false required: false
default: null
az: az:
description: description:
- "The availability zone for the subnet. Only required when state=present." - "The availability zone for the subnet. Only required when state=present."
required: false required: false
default: null
state: state:
description: description:
- Create or remove the subnet - Create or remove the subnet
required: true required: false
default: present default: present
choices: [ 'present', 'absent' ] choices: [ 'present', 'absent' ]
extends_documentation_fragment: aws extends_documentation_fragment: aws
@ -196,45 +198,43 @@ def ensure_subnet_absent(vpc_conn, vpc_id, cidr, check_mode):
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(
'resource_tags': {'type': 'dict', 'required': False}, vpc_id = dict(default=None, required=True),
'cidr': {'required': True}, resource_tags = dict(default=None, required=False, type='dict'),
'az': {}, cidr = dict(default=None, required=True),
'state': {'choices': ['present', 'absent'], 'default': 'present'}, az = dict(default=None, required=False),
}) 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:
vpc_conn = boto.vpc.connect_to_region( connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
region, except (boto.exception.NoAuthHandlerFound, StandardError), e:
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key
)
except boto.exception.NoAuthHandlerFound as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else:
module.fail_json(msg="region must be specified")
vpc_id = module.params.get('vpc_id') vpc_id = module.params.get('vpc_id')
tags = module.params.get('resource_tags') tags = module.params.get('resource_tags')
cidr = module.params.get('cidr') cidr = module.params.get('cidr')
az = module.params.get('az') az = module.params.get('az')
state = module.params.get('state', 'present') state = module.params.get('state')
try: try:
if state == 'present': if state == 'present':
result = ensure_subnet_present(vpc_conn, vpc_id, cidr, az, tags, result = ensure_subnet_present(connection, vpc_id, cidr, az, tags,
check_mode=module.check_mode) check_mode=module.check_mode)
elif state == 'absent': elif state == 'absent':
result = ensure_subnet_absent(vpc_conn, vpc_id, cidr, result = ensure_subnet_absent(connection, vpc_id, cidr,
check_mode=module.check_mode) check_mode=module.check_mode)
except AnsibleVPCSubnetException as e: except AnsibleVPCSubnetException as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))

Loading…
Cancel
Save