ec2_instance_info – List EC2 instances

Retrieve information about AWS EC2 instances.

Examples

- name: List all EC2 instances
  ec2_instance_info:
  register: result

- name: List a specific EC2 instance
  ec2_instance_info:
    ids: i-0c79884ded545df1a
  register: result

- name: List several EC2 instances according to their name tag
  ec2_instance_info:
    names:
      - app-server
      - db-server
  register: result

See Also

Parameters

ami (optional)

ID of the AMI used to launched the instance

type: str
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
filters (optional)

Filters to use when querying AWS resources. They must be provided as key/value pairs.

Keys and values are case-sensitive and must be strings.

Each key can have multiple values, provided as a list. Within these values, any value must match for the AWS resource to be included.

When multiple filters are provided, the result contains AWS resources matching all of them.

If a filter is specified in filters and also in another top-level parameter, the filter in the top-level parameter has precedence. The two are not merged.

If a module accepts a top-level parameter for querying the AWS resources, and you also specify the filter it corresponds to via filters, the top-level parameter has precedence.

type: dict
ids (optional)

Perform the operation for the specified resources.

type: list
names (optional)

Limit the results to the resources with specified names.

type: list
states (optional)

Limit the results to EC2 instances in the specified states.

By default, the module includes instances in all states except terminated.

This parameter cannot contain terminated, as terminated instances are treated as absent.

type: list
default: [‘pending’, ‘running’, ‘stopping’, ‘stopped’, ‘shutting-down’]
subnet (optional)

ID of the subnet where the instance is running.

type: str
type (optional)

Type of the EC2 instance.

type: str

Return Values

object (success), complex,

An object representing the EC2 Instance.

id (always), str, i-841b9271gd

ID of the EC2 instance.

launched_at (always), str, 2020-04-15T08:08:40+00:00

The time when instance was launched.

type (always), str, a1.xsmall

EC2 instance type.

ami (always), str, ami-0343ab73df9eb1496

ID of the AMI used to launched the instance.

vpc (always), str, vpc-129385ns2s2

ID of the VPC containing the instance.

subnet (always), str, subnet-14hs85ns83hg

ID of the subnet containing the instance.

availability_zone (always), str, az-use-1

ID of the availability zone for the instance.

security_groups (always), list, [‘sg-27fhs72gs922f’]

IDs of security groups associated with the instance.

network_interface (always), str, eni-2dfr38df335

ID of the instance’s primary network interface.

secondary_network_interfaces (always), list, []

IDs of the secondary network interfaces attached to the instance.

key_pair (always), str, my-key-pair

Name of the key pair to be used when connecting to the instance.

tenancy (always), str, default

The instance tenancy setting.

monitoring (always), str, detailed

CloudWatch monitoring mode for the instance.

on_instance_initiated_shutdown (always), str, terminate

The behavior when shut down is initiated from the instance.

state (always), str, running

State of the EC2 instance as reported by AWS.