mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix EIP release in ec2_vpc_nat_gateway (#20167)
* Check if EIP exists before deleting it After deleting the NAT gateway, the EIP sometimes seems to cease to exist afterwards. Check if it exists before deleting it. Otherwise you get: ``` Failed to release EIP eipalloc-abdc1234: An error occurred (InvalidAllocationID.NotFound) \ when calling the ReleaseAddress operation: The allocation ID 'eipalloc-abcd1234' does not \ exist", "success": false} ``` * Fix flake8 errors with ec2_vpc_nat_gateway
This commit is contained in:
parent
0d2d25b515
commit
950ff3f24a
1 changed files with 32 additions and 24 deletions
|
@ -14,6 +14,18 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import ec2_argument_spec, get_aws_connection_info, boto3_conn
|
||||
|
||||
import datetime
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
|
||||
from dateutil.tz import tzutc
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'status': ['preview'],
|
||||
'supported_by': 'community',
|
||||
'version': '1.0'}
|
||||
|
@ -216,12 +228,6 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
import datetime
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
|
||||
from dateutil.tz import tzutc
|
||||
|
||||
DRY_RUN_GATEWAYS = [
|
||||
{
|
||||
|
@ -662,11 +668,15 @@ def release_address(client, allocation_id, check_mode=False):
|
|||
return True, ''
|
||||
|
||||
ip_released = False
|
||||
params = {
|
||||
'AllocationId': allocation_id,
|
||||
}
|
||||
try:
|
||||
client.release_address(**params)
|
||||
client.describe_addresses(AllocationIds=[allocation_id])
|
||||
except botocore.exceptions.ClientError as e:
|
||||
# IP address likely already released
|
||||
# Happens with gateway in 'deleted' state that
|
||||
# still lists associations
|
||||
return True, str(e)
|
||||
try:
|
||||
client.release_address(AllocationId=allocation_id)
|
||||
ip_released = True
|
||||
except botocore.exceptions.ClientError as e:
|
||||
err_msg = str(e)
|
||||
|
@ -996,17 +1006,18 @@ def remove(client, nat_gateway_id, wait=False, wait_timeout=0,
|
|||
|
||||
def main():
|
||||
argument_spec = ec2_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
subnet_id=dict(type='str'),
|
||||
eip_address=dict(type='str'),
|
||||
allocation_id=dict(type='str'),
|
||||
if_exist_do_not_create=dict(type='bool', default=False),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
wait=dict(type='bool', default=False),
|
||||
wait_timeout=dict(type='int', default=320, required=False),
|
||||
release_eip=dict(type='bool', default=False),
|
||||
nat_gateway_id=dict(type='str'),
|
||||
client_token=dict(type='str'),
|
||||
argument_spec.update(
|
||||
dict(
|
||||
subnet_id=dict(type='str'),
|
||||
eip_address=dict(type='str'),
|
||||
allocation_id=dict(type='str'),
|
||||
if_exist_do_not_create=dict(type='bool', default=False),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
wait=dict(type='bool', default=False),
|
||||
wait_timeout=dict(type='int', default=320, required=False),
|
||||
release_eip=dict(type='bool', default=False),
|
||||
nat_gateway_id=dict(type='str'),
|
||||
client_token=dict(type='str'),
|
||||
)
|
||||
)
|
||||
module = AnsibleModule(
|
||||
|
@ -1081,9 +1092,6 @@ def main():
|
|||
msg=err_msg, success=success, changed=changed, **results
|
||||
)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue