diff --git a/lib/ansible/modules/extras/cloud/amazon/ec2_vpc_nat_gateway.py b/lib/ansible/modules/extras/cloud/amazon/ec2_vpc_nat_gateway.py index b6dca5fd9f6..848b27e52ed 100644 --- a/lib/ansible/modules/extras/cloud/amazon/ec2_vpc_nat_gateway.py +++ b/lib/ansible/modules/extras/cloud/amazon/ec2_vpc_nat_gateway.py @@ -62,6 +62,7 @@ options: description: - Deallocate the EIP from the VPC. - 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 default: true wait: @@ -159,6 +160,8 @@ EXAMPLES = ''' state: absent nat_gateway_id: nat-12345678 release_eip: yes + wait: yes + wait_timeout: 300 region: ap-southeast-2 ''' @@ -648,10 +651,11 @@ def release_address(client, allocation_id, check_mode=False): True Returns: - Boolean + Boolean, string """ + err_msg = '' if check_mode: - return True + return True, '' ip_released = False params = { @@ -660,10 +664,10 @@ def release_address(client, allocation_id, check_mode=False): try: client.release_address(**params) ip_released = True - except botocore.exceptions.ClientError: - pass + except botocore.exceptions.ClientError as e: + err_msg = str(e) - return ip_released + return ip_released, err_msg 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) if release_eip: - eip_released = ( - release_address(client, allocation_id, check_mode=check_mode) + eip_released, eip_err = ( + release_address(client, allocation_id, check_mode) ) 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 @@ -1037,7 +1045,6 @@ def main(): changed = False err_msg = '' - #Ensure resource is present if state == 'present': if not subnet_id: module.fail_json(msg='subnet_id is required for creation') diff --git a/lib/ansible/modules/extras/test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py b/lib/ansible/modules/extras/test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py index 7c4f163ad40..1b75c88a143 100644 --- a/lib/ansible/modules/extras/test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py +++ b/lib/ansible/modules/extras/test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py @@ -392,7 +392,7 @@ class AnsibleEc2VpcNatGatewayFunctions(unittest.TestCase): def test_release_address(self): client = boto3.client('ec2', region_name=aws_region) - success = ( + success, _ = ( ng.release_address( client, 'eipalloc-1234567', check_mode=True )