diff --git a/lib/ansible/modules/cloud/amazon/ec2_eni.py b/lib/ansible/modules/cloud/amazon/ec2_eni.py index 912f8a0e57f..eccc5b60acb 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_eni.py +++ b/lib/ansible/modules/cloud/amazon/ec2_eni.py @@ -97,6 +97,13 @@ options: - The number of secondary IP addresses to assign to the network interface. This option is mutually exclusive of secondary_private_ip_addresses required: false version_added: 2.2 + allow_reassignment: + description: + - Indicates whether to allow an IP address that is already assigned to another network interface or instance + to be reassigned to the specified network interface. + required: false + default: 'no' + version_added: 2.7 extends_documentation_fragment: - aws - ec2 @@ -365,6 +372,7 @@ def modify_eni(connection, vpc_id, module, eni): secondary_private_ip_addresses = module.params.get("secondary_private_ip_addresses") purge_secondary_private_ip_addresses = module.params.get("purge_secondary_private_ip_addresses") secondary_private_ip_address_count = module.params.get("secondary_private_ip_address_count") + allow_reassignment = module.params.get("allow_reassignment") changed = False try: @@ -401,7 +409,7 @@ def modify_eni(connection, vpc_id, module, eni): connection.assign_private_ip_addresses(network_interface_id=eni.id, private_ip_addresses=secondary_addresses_to_add, secondary_private_ip_address_count=None, - allow_reassignment=False, dry_run=False) + allow_reassignment=allow_reassignment, dry_run=False) changed = True if secondary_private_ip_address_count is not None: current_secondary_address_count = len(current_secondary_addresses) @@ -411,7 +419,7 @@ def modify_eni(connection, vpc_id, module, eni): private_ip_addresses=None, secondary_private_ip_address_count=(secondary_private_ip_address_count - current_secondary_address_count), - allow_reassignment=False, dry_run=False) + allow_reassignment=allow_reassignment, dry_run=False) changed = True elif secondary_private_ip_address_count < current_secondary_address_count: # How many of these addresses do we want to remove @@ -561,6 +569,7 @@ def main(): secondary_private_ip_addresses=dict(default=None, type='list'), purge_secondary_private_ip_addresses=dict(default=False, type='bool'), secondary_private_ip_address_count=dict(default=None, type='int'), + allow_reassignment=dict(default=False, type='bool'), attached=dict(default=None, type='bool') ) )