ec2_network_interface – Manage EC2 Elastic Network Interfaces

Create, update or delete an AWS EC2 Elastic Network Interface.

Examples

- name: Create a network interface in the default security group with an IP chosen by AWS
  ec2_network_interface:
    name: my-first-eni
    subnet: subnet-de593ab
    state: detached

- name: Create another network interface with custom settings and security groups
  ec2_network_interface:
    name: my-complicated-eni
    subnet: subnet-5ace7221
    ip: 192.0.2.158
    source_dest_check: false
    security_groups:
      - sg-06aa1300c4efeb57
      - sg-0b6f07cf42aasbde
    state: detached

- name: Create a network interface and attach it to an instance
  ec2_network_interface:
    name: my-attached-eni
    subnet: subnet-5afe1227
    ip: 198.51.100.85
    attachment:
      instance: i-18fg46a2dsd
      device_index: 5
      keep_on_termination: false
  register: attached_interface

- name: Detach a network interface from the instance
  ec2_network_interface:
    id: "{{ attached_interface.object.id }}"
    state: detached

- name: Modify a network interface's security groups
  ec2_network_interface:
    id: "{{ attached_interface.object.id }}"
    clear_security_groups: true
    security_groups:
      - sg-293474das3
    state: detached

- name: Remove a network interface
  ec2_network_interface:
    id: "{{ attached_interface.object.id }}"
    state: absent

Parameters

attachment (optional)

The configuration for an attachment of the network interface to an instance.

Required if state is attached.

type: dict
device_index (optional)

Attach the network interface to the instance at this index.

If this parameter is omitted, the first available device index is used.

type: int
instance (required)

The ID of the instance to attach the network interface to.

type: str
keep_on_termination (optional)

Whether the network interface should be present after the instance it is attached to is terminated.

type: bool
auth (optional)

Parameters for authenticating with the AWS service. Each of them may be defined via environment variables.

type: dict
access_key (optional)

The AWS access key ID. If not set, the value of the AWS_ACCESS_KEY environment variable will be checked.

Mutually exclusive with profile.

type: str
profile (optional)

The name of the AWS profile configured with aws configure.

Can be used instead of explicitly specifying your access credentials and region.

Use default to use the default profile.

Mutually exclusive with access_key and secret_key.

type: str
region (optional)

The name of the AWS region.

If not set, the value of the AWS_REGION environment variable will be checked.

If you set a profile that specifies a default region, that region is used and you can omit this parameter. Use this parameter to override the profile’s default region.

type: str
secret_key (optional)

The AWS secret access key. If not set, the value of the AWS_SECRET_KEY environment variable will be checked.

Mutually exclusive with profile.

type: str
url (optional)

The URL to the AWS service related to the resource. By default, this is automatically determined through the region parameter.

If not set explicitly, the value of the AWS_<SERVICE>_URL environment variable will be used.

The services currently supported are EC2 and S3.

type: str
clear_security_groups (optional)

Whether security groups not listed in security_groups should be removed from the network interface.

This parameter requires security_groups.

type: bool
clear_tags (optional)

Whether to clear any existing tags on the resource that are not explicitly stated in tags.

By default, existing tags are kept on the resource.

When this parameter is set to true, any pre-existing tags on the resource (including the name tag) are removed. To clear all tags except the name tag, make sure to provide the name parameter.

type: bool
description (optional)

An optional description of the network interface.

type: str
id (optional)

ID of the resource to perform the task on.

If specified, this parameter is used to identify the resource.

If omitted, a combination of subnet, ip, name, attachment.instance, attachment.device_index is used to identify an existing instance, if possible.

type: str
ip (optional)

The primary private IPv4 addresses for the network interface.

If provided, must be within the IP range of subnet.

When id is not present, it is used in combination with subnet to attempt to identify the network interface.

If this parameter is omitted, the private IPv4 address will be selected by AWS from the pool of available private IPv4 addresses from the subnet specified by the subnet parameter.

type: str
name (optional)

The name tag of the network interface.

Required for the creation of the network interface.

type: str
security_groups (optional)

List of security group IDs to attach the network interface to.

Security groups must reside in the same VPC as subnet.

If the parameter is provided, at least one security group must be specified.

Required if clear_security_groups is true.

If this parameter is omitted, the module will assume the default security group of the VPC in which the network interface exists.

type: list
source_dest_check (optional)

Whether to enable or disable source/destination checking for the network interface.

This must be set to false for interfaces used for NAT.

type: bool
state (optional)

The desired state of the network interface.

type: str
default: attached
choices: attached, detached, absent
subnet (optional)

The ID of the subnet in which to create the network interface.

Required when creating the network interface.

When id is not present, it is used in combination with ip to attempt to identify the network interface.

type: str
tags (optional)

Metadata for the AWS resource as key/value pairs.

Keys and values are case-sensitive.

type: dict
type (optional)

Type of the network interface.

Set this parameter to efa to create an Elastic Fabric Adapter instead of a regular network interface.

type: str
default: normal
choices: normal, efa

Return Values

object (success), dict, {‘object’: {‘id’: ‘eni-ba546d69’, ‘description’: ‘My First Elastic Network Interface.’, ‘subnet’: ‘subnet-faff387’, ‘security_groups’: [‘sg-1’], ‘type’: ‘normal’, ‘tags’: {‘Name’: ‘myfirsteni’}, ‘mac_address’: ‘00:05:B0:E9:E7:D0’, ‘attachment’: {‘instance’: ‘i-b856a2857fadfa’, ‘device_index’: 0, ‘keep_on_termination’: False}, ‘public_ip’: None, ‘ip’: ‘192.0.2.58’, ‘source_dest_check’: True}})

A representation of the EC2 network interface.

id (always), str, )

The ID of the network interface

description (always), str, )

The description of the network interface, if any.

subnet (always), str, )

The ID of the subnet this network interface is assigned to.

security_groups (always), list, )

The IDs of security groups assigned to this network interface. At least one.

type (always), str, )

The type of this network interface.

tags (always), dict, )

The tags assigned to this network interface.

mac_address (always), str, )

The MAC address of this network interface.

attachment (when I(state=attached)), dict, )

The attachment to an instance, if any.

instance (always), str, )

The ID of the instance the network interface is attached to.

device_index (always), str, )

The hardware device index the network interface is attached to.

keep_on_termination (always), str, )

Whether the network interface is preserved when terminating the instance.

public_ip (always), str, )

The public IPv4 address or the VPC address (Elastic IP) associated with this network interface, if any.

ip (always), str, )

The primary private IPv4 address assigned to this network interface.

source_dest_check (always), bool, )

Whether source-destination checking is enabled for this network interface.