1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Updated documentation and added boto profile support.

This commit is contained in:
Rob White 2015-06-14 16:31:31 +10:00 committed by Matt Clay
parent b180b97273
commit 4ad6cc183a

View file

@ -1,75 +1,42 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible
# #
# Ansible is free software: you can redistribute it and/or modify # This is a free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# Ansible is distributed in the hope that it will be useful, # This Ansible library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with this library. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: ec2_vpc_igw module: ec2_vpc_igw
short_description: configure AWS virtual private clouds short_description: Manage an AWS VPC Internet gateway
description: description:
- Create or terminates AWS internat gateway in a virtual private cloud. ''' - Manage an AWS VPC Internet gateway
'''This module has a dependency on python-boto. version_added: "2.0"
version_added: "1.8" author: Robert Estelle, @erydo
options: options:
vpc_id: vpc_id:
description: description:
- "The VPC ID for which to create or remove the Internet Gateway." - The VPC ID for the VPC in which to manage the Internet Gateway.
required: true required: true
default: null
state: state:
description: description:
- Create or terminate the IGW - Create or terminate the IGW
required: true required: false
default: present default: present
aliases: [] extends_documentation_fragment: aws
region:
description:
- region in which the resource exists.
required: false
default: null
aliases: ['aws_region', 'ec2_region']
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY'''
''' environment variable is used.
required: false
default: None
aliases: ['ec2_secret_key', 'secret_key' ]
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY'''
''' environment variable is used.
required: false
default: None
aliases: ['ec2_access_key', 'access_key' ]
validate_certs:
description:
- When set to "no", SSL certificates will not be validated for boto'''
''' versions >= 2.6.0.
required: false
default: "yes"
choices: ["yes", "no"]
aliases: []
version_added: "1.5"
requirements: [ "boto" ]
author: Robert Estelle
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Note: None of these examples set aws_access_key, aws_secret_key, or region. # Note: These examples do not set authentication details, see the AWS Guide for details.
# It is assumed that their matching environment variables are set.
# Ensure that the VPC has an Internet Gateway. # Ensure that the VPC has an Internet Gateway.
# The Internet Gateway ID is can be accessed via {{igw.gateway_id}} for use # The Internet Gateway ID is can be accessed via {{igw.gateway_id}} for use
@ -147,40 +114,39 @@ def ensure_igw_present(vpc_conn, vpc_id, 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(
'state': {'choices': ['present', 'absent'], 'default': 'present'}, vpc_id = dict(required=True),
}) state = dict(choices=['present', 'absent'], default='present')
)
)
module = AnsibleModule( module = AnsibleModule(
argument_spec=argument_spec, argument_spec=argument_spec,
supports_check_mode=True, 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')
try: if region:
vpc_conn = boto.vpc.connect_to_region( try:
region, connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
aws_access_key_id=aws_access_key, except (boto.exception.NoAuthHandlerFound, StandardError), e:
aws_secret_access_key=aws_secret_key module.fail_json(msg=str(e))
) else:
except boto.exception.NoAuthHandlerFound as e: module.fail_json(msg="region must be specified")
module.fail_json(msg=str(e))
vpc_id = module.params.get('vpc_id') vpc_id = module.params.get('vpc_id')
state = module.params.get('state', 'present') state = module.params.get('state', 'present')
try: try:
if state == 'present': if state == 'present':
result = ensure_igw_present(vpc_conn, vpc_id, result = ensure_igw_present(connection, vpc_id, check_mode=module.check_mode)
check_mode=module.check_mode)
elif state == 'absent': elif state == 'absent':
result = ensure_igw_absent(vpc_conn, vpc_id, result = ensure_igw_absent(connection, vpc_id, check_mode=module.check_mode)
check_mode=module.check_mode)
except AnsibleIGWException as e: except AnsibleIGWException as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))