fixed error message for releasing an ip when not waiting for the nat gateway to delete successfully 1st

reviewable/pr18780/r1
Allen Sanabria 8 years ago
parent dcf4d7e6e5
commit 950d76af0b

@ -62,6 +62,7 @@ options:
description: description:
- Deallocate the EIP from the VPC. - Deallocate the EIP from the VPC.
- Option is only valid with the absent state. - Option is only valid with the absent state.
- You should use this with the wait option. Since you can not release an address while a delete operation is happening.
required: false required: false
default: true default: true
wait: wait:
@ -159,6 +160,8 @@ EXAMPLES = '''
state: absent state: absent
nat_gateway_id: nat-12345678 nat_gateway_id: nat-12345678
release_eip: yes release_eip: yes
wait: yes
wait_timeout: 300
region: ap-southeast-2 region: ap-southeast-2
''' '''
@ -648,10 +651,11 @@ def release_address(client, allocation_id, check_mode=False):
True True
Returns: Returns:
Boolean Boolean, string
""" """
err_msg = ''
if check_mode: if check_mode:
return True return True, ''
ip_released = False ip_released = False
params = { params = {
@ -660,10 +664,10 @@ def release_address(client, allocation_id, check_mode=False):
try: try:
client.release_address(**params) client.release_address(**params)
ip_released = True ip_released = True
except botocore.exceptions.ClientError: except botocore.exceptions.ClientError as e:
pass err_msg = str(e)
return ip_released return ip_released, err_msg
def create(client, subnet_id, allocation_id, client_token=None, def create(client, subnet_id, allocation_id, client_token=None,
@ -973,11 +977,15 @@ def remove(client, nat_gateway_id, wait=False, wait_timeout=0,
err_msg = str(e) err_msg = str(e)
if release_eip: if release_eip:
eip_released = ( eip_released, eip_err = (
release_address(client, allocation_id, check_mode=check_mode) release_address(client, allocation_id, check_mode)
) )
if not eip_released: if not eip_released:
err_msg = "Failed to release EIP %s".format(allocation_id) err_msg = (
"{0}: Failed to release EIP {1}: {2}"
.format(err_msg, allocation_id, eip_err)
)
success = False
return success, changed, err_msg, results return success, changed, err_msg, results
@ -1037,7 +1045,6 @@ def main():
changed = False changed = False
err_msg = '' err_msg = ''
#Ensure resource is present
if state == 'present': if state == 'present':
if not subnet_id: if not subnet_id:
module.fail_json(msg='subnet_id is required for creation') module.fail_json(msg='subnet_id is required for creation')

@ -392,7 +392,7 @@ class AnsibleEc2VpcNatGatewayFunctions(unittest.TestCase):
def test_release_address(self): def test_release_address(self):
client = boto3.client('ec2', region_name=aws_region) client = boto3.client('ec2', region_name=aws_region)
success = ( success, _ = (
ng.release_address( ng.release_address(
client, 'eipalloc-1234567', check_mode=True client, 'eipalloc-1234567', check_mode=True
) )

Loading…
Cancel
Save