updates to Documentation - Removed refs to Boto, added params dict() and removed obsolete if statements
This commit is contained in:
parent
34ae687ae3
commit
f6c7bdf9c5
1 changed files with 23 additions and 50 deletions
|
@ -39,29 +39,6 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: present
|
default: present
|
||||||
choices: ['present', 'absent', 'accept', 'reject']
|
choices: ['present', 'absent', 'accept', 'reject']
|
||||||
region:
|
|
||||||
description:
|
|
||||||
- The AWS region to use. Must be specified if ec2_url is not used. If not specified then the value of the EC2_REGION environment variable, if any, is used.
|
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
aliases: ['aws_region', 'ec2_region']
|
|
||||||
profile:
|
|
||||||
description:
|
|
||||||
- boto3 profile name.
|
|
||||||
required: false
|
|
||||||
default: None
|
|
||||||
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']
|
|
||||||
author: Mike Mochan(@mmochan)
|
author: Mike Mochan(@mmochan)
|
||||||
extends_documentation_fragment: aws
|
extends_documentation_fragment: aws
|
||||||
'''
|
'''
|
||||||
|
@ -170,21 +147,14 @@ EXAMPLES = '''
|
||||||
'''
|
'''
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
task:
|
task:
|
||||||
description: details about the tast that was started
|
description: The result of the create, accept, reject or delete action.
|
||||||
type: complex
|
returned: success
|
||||||
sample: "TODO: include sample"
|
type: dictionary
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
import datetime
|
|
||||||
import boto
|
|
||||||
import botocore
|
import botocore
|
||||||
HAS_BOTO = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_BOTO = False
|
|
||||||
|
|
||||||
try:
|
|
||||||
import boto3
|
import boto3
|
||||||
HAS_BOTO3 = True
|
HAS_BOTO3 = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -220,6 +190,13 @@ def peer_status(resource, module):
|
||||||
|
|
||||||
def create_peer_connection(client, module):
|
def create_peer_connection(client, module):
|
||||||
changed = False
|
changed = False
|
||||||
|
params = dict()
|
||||||
|
params['VpcId'] = module.params.get('vpc_id')
|
||||||
|
params['PeerVpcId'] = module.params.get('peer_vpc_id')
|
||||||
|
if module.params.get('peer_owner_id'):
|
||||||
|
params['PeerOwnerId'] = str(module.params.get('peer_owner_id'))
|
||||||
|
params['DryRun'] = module.check_mode
|
||||||
|
|
||||||
vpc_id = module.params.get('vpc_id')
|
vpc_id = module.params.get('vpc_id')
|
||||||
peer_vpc_id = module.params.get('peer_vpc_id')
|
peer_vpc_id = module.params.get('peer_vpc_id')
|
||||||
peer_owner_id = module.params.get('peer_owner_id', False)
|
peer_owner_id = module.params.get('peer_owner_id', False)
|
||||||
|
@ -229,15 +206,8 @@ def create_peer_connection(client, module):
|
||||||
return (False, peering_conn['VpcPeeringConnectionId'])
|
return (False, peering_conn['VpcPeeringConnectionId'])
|
||||||
if is_pending(peering_conn):
|
if is_pending(peering_conn):
|
||||||
return (False, peering_conn['VpcPeeringConnectionId'])
|
return (False, peering_conn['VpcPeeringConnectionId'])
|
||||||
if not peer_owner_id:
|
|
||||||
try:
|
try:
|
||||||
peering_conn = client.create_vpc_peering_connection(VpcId=vpc_id, PeerVpcId=peer_vpc_id)
|
peering_conn = client.create_vpc_peering_connection(**params)
|
||||||
return (True, peering_conn['VpcPeeringConnection']['VpcPeeringConnectionId'])
|
|
||||||
except botocore.exceptions.ClientError as e:
|
|
||||||
module.fail_json(msg=str(e))
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
peering_conn = client.create_vpc_peering_connection(VpcId=vpc_id, PeerVpcId=peer_vpc_id, PeerOwnerId=str(peer_owner_id))
|
|
||||||
return (True, peering_conn['VpcPeeringConnection']['VpcPeeringConnectionId'])
|
return (True, peering_conn['VpcPeeringConnection']['VpcPeeringConnectionId'])
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
@ -245,19 +215,23 @@ def create_peer_connection(client, module):
|
||||||
|
|
||||||
def accept_reject_delete(state, client, resource, module):
|
def accept_reject_delete(state, client, resource, module):
|
||||||
changed = False
|
changed = False
|
||||||
|
params = dict()
|
||||||
|
params['VpcPeeringConnectionId'] = module.params.get('peering_id')
|
||||||
|
params['DryRun'] = module.check_mode
|
||||||
|
|
||||||
peer_id = module.params.get('peering_id')
|
peer_id = module.params.get('peering_id')
|
||||||
if state == "accept":
|
if state == "accept":
|
||||||
if peer_status(resource, module) == "Active":
|
if peer_status(resource, module) == "Active":
|
||||||
return (False, peer_id)
|
return (False, peer_id)
|
||||||
try:
|
try:
|
||||||
client.accept_vpc_peering_connection(VpcPeeringConnectionId=peer_id)
|
client.accept_vpc_peering_connection(**params)
|
||||||
return (True, peer_id)
|
return (True, peer_id)
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
if state == "reject":
|
if state == "reject":
|
||||||
if peer_status(resource, module) != "Active":
|
if peer_status(resource, module) != "Active":
|
||||||
try:
|
try:
|
||||||
client.reject_vpc_peering_connection(VpcPeeringConnectionId=peer_id)
|
client.reject_vpc_peering_connection(**params)
|
||||||
return (True, peer_id)
|
return (True, peer_id)
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
@ -265,7 +239,7 @@ def accept_reject_delete(state, client, resource, module):
|
||||||
return (False, peer_id)
|
return (False, peer_id)
|
||||||
if state == "absent":
|
if state == "absent":
|
||||||
try:
|
try:
|
||||||
client.delete_vpc_peering_connection(VpcPeeringConnectionId=peer_id)
|
client.delete_vpc_peering_connection(**params)
|
||||||
return (True, peer_id)
|
return (True, peer_id)
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
@ -275,18 +249,17 @@ def accept_reject_delete(state, client, resource, module):
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ec2_argument_spec()
|
argument_spec = ec2_argument_spec()
|
||||||
argument_spec.update(dict(
|
argument_spec.update(dict(
|
||||||
region=dict(),
|
|
||||||
vpc_id=dict(),
|
vpc_id=dict(),
|
||||||
peer_vpc_id=dict(),
|
peer_vpc_id=dict(),
|
||||||
peer_owner_id=dict(),
|
|
||||||
peering_id=dict(),
|
peering_id=dict(),
|
||||||
|
peer_owner_id=dict(),
|
||||||
profile=dict(),
|
profile=dict(),
|
||||||
state=dict(default='present', choices=['present', 'absent', 'accept', 'reject'])
|
state=dict(default='present', choices=['present', 'absent', 'accept', 'reject'])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
module = AnsibleModule(argument_spec=argument_spec)
|
module = AnsibleModule(argument_spec=argument_spec)
|
||||||
|
|
||||||
if not (HAS_BOTO or HAS_BOTO3):
|
if not HAS_BOTO3:
|
||||||
module.fail_json(msg='json and boto/boto3 is required.')
|
module.fail_json(msg='json and boto/boto3 is required.')
|
||||||
state = module.params.get('state').lower()
|
state = module.params.get('state').lower()
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue