amazon.aws.ec2_eni module – Create and optionally attach an Elastic Network Interface (ENI) to an instance
Note
This module is part of the amazon.aws collection (version 2.3.0).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install amazon.aws
.
To use it in a playbook, specify: amazon.aws.ec2_eni
.
New in version 1.0.0: of amazon.aws
Synopsis
Create and optionally attach an Elastic Network Interface (ENI) to an instance. If an ENI ID or private_ip is provided, the existing ENI (if any) will be modified. The ‘attached’ parameter controls the attachment status of the network interface.
Requirements
The below requirements are needed on the host that executes this module.
python >= 3.6
boto3 >= 1.15.0
botocore >= 1.18.0
Parameters
Parameter |
Comments |
---|---|
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. Choices:
|
|
Specifies if network interface should be attached or detached from instance. If omitted, attachment status won’t change Choices:
|
|
If profile is set this parameter is ignored. Passing the aws_access_key and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01. |
|
The location of a CA Bundle to use when validating SSL certificates. Not used by boto 2 based modules. Note: The CA Bundle is read ‘module’ side and may need to be explicitly copied from the controller if not run locally. |
|
A dictionary to modify the botocore configuration. Parameters can be found at https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config. Only the ‘user_agent’ key is used for boto modules. See http://boto.cloudhackers.com/en/latest/boto_config_tut.html#boto for more boto configuration. |
|
If profile is set this parameter is ignored. Passing the aws_secret_key and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01. |
|
Use a botocore.endpoint logger to parse the unique (rather than total) “resource:action” API calls made during a task, outputing the set to the resource_actions key in the task results. Use the aws_resource_action callback to output to total list made during a playbook. The ANSIBLE_DEBUG_BOTOCORE_LOGS environment variable may also be used. Choices:
|
|
Delete the interface when the instance it is attached to is terminated. You can only specify this flag when the interface is being modified, not on creation. Choices:
|
|
Optional description of the ENI. |
|
The index of the device for the network interface attachment on the instance. Default: 0 |
|
URL to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Ignored for modules where region is required. Must be specified for all other modules if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used. |
|
The ID of the ENI (to modify). If eni_id=None and state=present, a new eni will be created. |
|
Force detachment of the interface. This applies either when explicitly detaching the interface by setting instance_id=None or when deleting an interface with state=absent. Choices:
|
|
Instance ID that you wish to attach ENI to. Since version 2.2, use the attached parameter to attach or detach an ENI. Prior to 2.2, to detach an ENI from an instance, use |
|
Name for the ENI. This will create a tag called “Name” with the value assigned here. This can be used in conjunction with subnet_id as another means of identifiying a network interface. AWS does not enforce unique Name tags, so duplicate names are possible if you configure it that way. If that is the case, you will need to provide other identifying information such as private_ip_address or eni_id. |
|
Private IP address. |
|
Using profile will override aws_access_key, aws_secret_key and security_token and support for passing them at the same time as profile has been deprecated. aws_access_key, aws_secret_key and security_token will be made mutually exclusive with profile after 2022-06-01. |
|
To be used with secondary_private_ip_addresses to determine whether or not to remove any secondary IP addresses other than those specified. Set secondary_private_ip_addresses=[] to purge all secondary addresses. Choices:
|
|
Indicates whether to remove tags not specified in tags or name. This means you have to specify all the desired tags on each task affecting a network interface. If tags is omitted or None this option is disregarded. Choices:
|
|
The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used. See http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region |
|
The number of secondary IP addresses to assign to the network interface. This option is mutually exclusive of secondary_private_ip_addresses |
|
A list of IP addresses to assign as secondary IP addresses to the network interface. This option is mutually exclusive of secondary_private_ip_address_count |
|
List of security groups associated with the interface. Only used when state=present. Since version 2.2, you can specify security groups by ID or by name or a combination of both. Prior to 2.2, you can specify only by ID. |
|
If profile is set this parameter is ignored. Passing the security_token and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01. |
|
By default, interfaces perform source/destination checks. NAT instances however need this check to be disabled. You can only specify this flag when the interface is being modified, not on creation. Choices:
|
|
Create or delete ENI. Choices:
|
|
ID of subnet in which to create the ENI. |
|
A hash/dictionary of tags to add to the new ENI or to add/remove from an existing one. Please note that the name field sets the “Name” tag. To clear all tags, set this option to an empty dictionary to use in conjunction with purge_tags. If you provide name, that tag will not be removed. To prevent removing any tags set purge_tags to false. |
|
When set to “no”, SSL certificates will not be validated for communication with the AWS APIs. Choices:
|
Notes
Note
This module identifies and ENI based on either the eni_id, a combination of private_ip_address and subnet_id, or a combination of instance_id and device_id. Any of these options will let you specify a particular ENI.
If parameters are not set within the module, the following environment variables can be used in decreasing order of precedence
AWS_URL
orEC2_URL
,AWS_PROFILE
orAWS_DEFAULT_PROFILE
,AWS_ACCESS_KEY_ID
orAWS_ACCESS_KEY
orEC2_ACCESS_KEY
,AWS_SECRET_ACCESS_KEY
orAWS_SECRET_KEY
orEC2_SECRET_KEY
,AWS_SECURITY_TOKEN
orEC2_SECURITY_TOKEN
,AWS_REGION
orEC2_REGION
,AWS_CA_BUNDLE
When no credentials are explicitly provided the AWS SDK (boto3) that Ansible uses will fall back to its configuration files (typically
~/.aws/credentials
). See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html for more information.Modules based on the original AWS SDK (boto) may read their default configuration from different files. See https://boto.readthedocs.io/en/latest/boto_config_tut.html for more information.
AWS_REGION
orEC2_REGION
can be typically be used to specify the AWS region, when required, but this can also be defined in the configuration files.
Examples
# Note: These examples do not set authentication details, see the AWS Guide for details.
# Create an ENI. As no security group is defined, ENI will be created in default security group
- amazon.aws.ec2_eni:
private_ip_address: 172.31.0.20
subnet_id: subnet-xxxxxxxx
state: present
# Create an ENI and attach it to an instance
- amazon.aws.ec2_eni:
instance_id: i-xxxxxxx
device_index: 1
private_ip_address: 172.31.0.20
subnet_id: subnet-xxxxxxxx
state: present
# Create an ENI with two secondary addresses
- amazon.aws.ec2_eni:
subnet_id: subnet-xxxxxxxx
state: present
secondary_private_ip_address_count: 2
# Assign a secondary IP address to an existing ENI
# This will purge any existing IPs
- amazon.aws.ec2_eni:
subnet_id: subnet-xxxxxxxx
eni_id: eni-yyyyyyyy
state: present
secondary_private_ip_addresses:
- 172.16.1.1
# Remove any secondary IP addresses from an existing ENI
- amazon.aws.ec2_eni:
subnet_id: subnet-xxxxxxxx
eni_id: eni-yyyyyyyy
state: present
secondary_private_ip_address_count: 0
# Destroy an ENI, detaching it from any instance if necessary
- amazon.aws.ec2_eni:
eni_id: eni-xxxxxxx
force_detach: true
state: absent
# Update an ENI
- amazon.aws.ec2_eni:
eni_id: eni-xxxxxxx
description: "My new description"
state: present
# Update an ENI using name and subnet_id
- amazon.aws.ec2_eni:
name: eni-20
subnet_id: subnet-xxxxxxx
description: "My new description"
state: present
# Update an ENI identifying it by private_ip_address and subnet_id
- amazon.aws.ec2_eni:
subnet_id: subnet-xxxxxxx
private_ip_address: 172.16.1.1
description: "My new description"
# Detach an ENI from an instance
- amazon.aws.ec2_eni:
eni_id: eni-xxxxxxx
instance_id: None
state: present
### Delete an interface on termination
# First create the interface
- amazon.aws.ec2_eni:
instance_id: i-xxxxxxx
device_index: 1
private_ip_address: 172.31.0.20
subnet_id: subnet-xxxxxxxx
state: present
register: eni
# Modify the interface to enable the delete_on_terminaton flag
- amazon.aws.ec2_eni:
eni_id: "{{ eni.interface.id }}"
delete_on_termination: true
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Network interface attributes Returned: when state != absent |
|
interface description Returned: success Sample: “Firewall network interface” |
|
list of security groups Returned: success Sample: [{“sg-f8a8a9da”: “default”}] |
|
network interface id Returned: success Sample: “eni-1d889198” |
|
interface’s physical address Returned: success Sample: “00:00:5E:00:53:23” |
|
The name of the ENI Returned: success Sample: “my-eni-20” |
|
aws account id Returned: success Sample: 812381371 |
|
primary ip address of this interface Returned: success Sample: “10.20.30.40” |
|
list of all private ip addresses associated to this interface Returned: success Sample: [{“primary_address”: true, “private_ip_address”: “10.20.30.40”}] |
|
value of source/dest check flag Returned: success Sample: true |
|
network interface status Returned: success Sample: “pending” |
|
which vpc subnet the interface is bound Returned: success Sample: “subnet-b0a0393c” |
|
The dictionary of tags associated with the ENI Returned: success Sample: {“Name”: “my-eni”, “group”: “Finance”} |
|
which vpc this network interface is bound Returned: success Sample: “vpc-9a9a9da” |
Authors
Rob White (@wimnat)
Mike Healey (@healem)