community.aws.ec2_instance_info (1.1.0) — module

Gather information about ec2 instances in AWS

| "added in version" 1.0.0 of community.aws"

Authors: Michael Schuett (@michaeljs1990), Rob White (@wimnat)

Install collection

Install with ansible-galaxy collection install community.aws:==1.1.0


Add to requirements.yml

  collections:
    - name: community.aws
      version: 1.1.0

Description

Gather information about ec2 instances in AWS

This module was called C(ec2_instance_facts) before Ansible 2.9. The usage did not change.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Note: These examples do not set authentication details, see the AWS Guide for details.

- name: Gather information about all instances
  community.aws.ec2_instance_info:
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Gather information about all instances in AZ ap-southeast-2a
  community.aws.ec2_instance_info:
    filters:
      availability-zone: ap-southeast-2a
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Gather information about a particular instance using ID
  community.aws.ec2_instance_info:
    instance_ids:
      - i-12345678
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Gather information about any instance with a tag key Name and value Example
  community.aws.ec2_instance_info:
    filters:
      "tag:Name": Example
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Gather information about any instance in states "shutting-down", "stopping", "stopped"
  community.aws.ec2_instance_info:
    filters:
      instance-state-name: [ "shutting-down", "stopping", "stopped" ]

Inputs

    
region:
    aliases:
    - aws_region
    - ec2_region
    description:
    - The AWS region to use.
    - For global services such as IAM, Route53 and CloudFront, I(region) is ignored.
    - The C(AWS_REGION) or C(EC2_REGION) environment variables may also be used.
    - See the Amazon AWS documentation for more information U(http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region).
    - The C(ec2_region) alias has been deprecated and will be removed in a release after
      2024-12-01
    - Support for the C(EC2_REGION) environment variable has been deprecated and will
      be removed in a release after 2024-12-01.
    type: str

filters:
    default: {}
    description:
    - A dict of filters to apply. Each dict item consists of a filter key and a filter
      value. See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html)
      for possible filters. Filter names and values are case sensitive.
    required: false
    type: dict

profile:
    aliases:
    - aws_profile
    description:
    - A named AWS profile to use for authentication.
    - See the AWS documentation for more information about named profiles U(https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html).
    - The C(AWS_PROFILE) environment variable may also be used.
    - The I(profile) option is mutually exclusive with the I(aws_access_key), I(aws_secret_key)
      and I(security_token) options.
    type: str

access_key:
    aliases:
    - aws_access_key_id
    - aws_access_key
    - ec2_access_key
    description:
    - AWS access key ID.
    - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys).
    - The C(AWS_ACCESS_KEY_ID), C(AWS_ACCESS_KEY) or C(EC2_ACCESS_KEY) environment variables
      may also be used in decreasing order of preference.
    - The I(aws_access_key) and I(profile) options are mutually exclusive.
    - The I(aws_access_key_id) alias was added in release 5.1.0 for consistency with the
      AWS botocore SDK.
    - The I(ec2_access_key) alias has been deprecated and will be removed in a release
      after 2024-12-01.
    - Support for the C(EC2_ACCESS_KEY) environment variable has been deprecated and will
      be removed in a release after 2024-12-01.
    type: str

aws_config:
    description:
    - A dictionary to modify the botocore configuration.
    - Parameters can be found in the AWS documentation U(https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config).
    type: dict

secret_key:
    aliases:
    - aws_secret_access_key
    - aws_secret_key
    - ec2_secret_key
    description:
    - AWS secret access key.
    - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys).
    - The C(AWS_SECRET_ACCESS_KEY), C(AWS_SECRET_KEY), or C(EC2_SECRET_KEY) environment
      variables may also be used in decreasing order of preference.
    - The I(secret_key) and I(profile) options are mutually exclusive.
    - The I(aws_secret_access_key) alias was added in release 5.1.0 for consistency with
      the AWS botocore SDK.
    - The I(ec2_secret_key) alias has been deprecated and will be removed in a release
      after 2024-12-01.
    - Support for the C(EC2_SECRET_KEY) environment variable has been deprecated and will
      be removed in a release after 2024-12-01.
    type: str

endpoint_url:
    aliases:
    - ec2_url
    - aws_endpoint_url
    - s3_url
    description:
    - URL to connect to instead of the default AWS endpoints.  While this can be used
      to connection to other AWS-compatible services the amazon.aws and community.aws
      collections are only tested against AWS.
    - The  C(AWS_URL) or C(EC2_URL) environment variables may also be used, in decreasing
      order of preference.
    - The I(ec2_url) and I(s3_url) aliases have been deprecated and will be removed in
      a release after 2024-12-01.
    - Support for the C(EC2_URL) environment variable has been deprecated and will be
      removed in a release after 2024-12-01.
    type: str

instance_ids:
    description:
    - If you specify one or more instance IDs, only instances that have the specified
      IDs are returned.
    elements: str
    required: false
    type: list

aws_ca_bundle:
    description:
    - The location of a CA Bundle to use when validating SSL certificates.
    - The C(AWS_CA_BUNDLE) environment variable may also be used.
    type: path

session_token:
    aliases:
    - aws_session_token
    - security_token
    - aws_security_token
    - access_token
    description:
    - AWS STS session token for use with temporary credentials.
    - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys).
    - The C(AWS_SESSION_TOKEN), C(AWS_SECURITY_TOKEN) or C(EC2_SECURITY_TOKEN) environment
      variables may also be used in decreasing order of preference.
    - The I(security_token) and I(profile) options are mutually exclusive.
    - Aliases I(aws_session_token) and I(session_token) were added in release 3.2.0, with
      the parameter being renamed from I(security_token) to I(session_token) in release
      6.0.0.
    - The I(security_token), I(aws_security_token), and I(access_token) aliases have been
      deprecated and will be removed in a release after 2024-12-01.
    - Support for the C(EC2_SECRET_KEY) and C(AWS_SECURITY_TOKEN) environment variables
      has been deprecated and will be removed in a release after 2024-12-01.
    type: str

validate_certs:
    default: true
    description:
    - When set to C(false), SSL certificates will not be validated for communication with
      the AWS APIs.
    - Setting I(validate_certs=false) is strongly discouraged, as an alternative, consider
      setting I(aws_ca_bundle) instead.
    type: bool

debug_botocore_endpoint_logs:
    default: false
    description:
    - Use a C(botocore.endpoint) logger to parse the unique (rather than total) C("resource:action")
      API calls made during a task, outputing the set to the resource_actions key in the
      task results. Use the C(aws_resource_action) callback to output to total list made
      during a playbook.
    - The C(ANSIBLE_DEBUG_BOTOCORE_LOGS) environment variable may also be used.
    type: bool

Outputs

instances:
  contains:
    ami_launch_index:
      description: The AMI launch index, which can be used to find this instance in
        the launch group.
      returned: always
      sample: 0
      type: int
    architecture:
      description: The architecture of the image
      returned: always
      sample: x86_64
      type: str
    block_device_mappings:
      contains:
        device_name:
          description: The device name exposed to the instance (for example, /dev/sdh
            or xvdh).
          returned: always
          sample: /dev/sdh
          type: str
        ebs:
          contains:
            attach_time:
              description: The time stamp when the attachment initiated.
              returned: always
              sample: '2017-03-23T22:51:24+00:00'
              type: str
            delete_on_termination:
              description: Indicates whether the volume is deleted on instance termination.
              returned: always
              sample: true
              type: bool
            status:
              description: The attachment state.
              returned: always
              sample: attached
              type: str
            volume_id:
              description: The ID of the EBS volume
              returned: always
              sample: vol-12345678
              type: str
          description: Parameters used to automatically set up EBS volumes when the
            instance is launched.
          returned: always
          type: complex
      description: Any block device mapping entries for the instance.
      returned: always
      type: complex
    client_token:
      description: The idempotency token you provided when you launched the instance,
        if applicable.
      returned: always
      sample: mytoken
      type: str
    cpu_options:
      contains:
        core_count:
          description: The number of CPU cores for the instance.
          returned: always
          sample: 1
          type: int
        threads_per_core:
          description: The number of threads per CPU core. On supported instance,
            a value of 1 means Intel Hyper-Threading Technology is disabled.
          returned: always
          sample: 1
          type: int
      description: The CPU options set for the instance.
      returned: always if botocore version >= 1.10.16
      type: complex
    ebs_optimized:
      description: Indicates whether the instance is optimized for EBS I/O.
      returned: always
      sample: false
      type: bool
    hypervisor:
      description: The hypervisor type of the instance.
      returned: always
      sample: xen
      type: str
    iam_instance_profile:
      contains:
        arn:
          description: The Amazon Resource Name (ARN) of the instance profile.
          returned: always
          sample: arn:aws:iam::000012345678:instance-profile/myprofile
          type: str
        id:
          description: The ID of the instance profile
          returned: always
          sample: JFJ397FDG400FG9FD1N
          type: str
      description: The IAM instance profile associated with the instance, if applicable.
      returned: always
      type: complex
    image_id:
      description: The ID of the AMI used to launch the instance.
      returned: always
      sample: ami-0011223344
      type: str
    instance_id:
      description: The ID of the instance.
      returned: always
      sample: i-012345678
      type: str
    instance_type:
      description: The instance type size of the running instance.
      returned: always
      sample: t2.micro
      type: str
    key_name:
      description: The name of the key pair, if this instance was launched with an
        associated key pair.
      returned: always
      sample: my-key
      type: str
    launch_time:
      description: The time the instance was launched.
      returned: always
      sample: '2017-03-23T22:51:24+00:00'
      type: str
    monitoring:
      contains:
        state:
          description: Indicates whether detailed monitoring is enabled. Otherwise,
            basic monitoring is enabled.
          returned: always
          sample: disabled
          type: str
      description: The monitoring for the instance.
      returned: always
      type: complex
    network_interfaces:
      contains:
        association:
          contains:
            ip_owner_id:
              description: The ID of the owner of the Elastic IP address.
              returned: always
              sample: amazon
              type: str
            public_dns_name:
              description: The public DNS name.
              returned: always
              sample: ''
              type: str
            public_ip:
              description: The public IP address or Elastic IP address bound to the
                network interface.
              returned: always
              sample: 1.2.3.4
              type: str
          description: The association information for an Elastic IPv4 associated
            with the network interface.
          returned: always
          type: complex
        attachment:
          contains:
            attach_time:
              description: The time stamp when the attachment initiated.
              returned: always
              sample: '2017-03-23T22:51:24+00:00'
              type: str
            attachment_id:
              description: The ID of the network interface attachment.
              returned: always
              sample: eni-attach-3aff3f
              type: str
            delete_on_termination:
              description: Indicates whether the network interface is deleted when
                the instance is terminated.
              returned: always
              sample: true
              type: bool
            device_index:
              description: The index of the device on the instance for the network
                interface attachment.
              returned: always
              sample: 0
              type: int
            status:
              description: The attachment state.
              returned: always
              sample: attached
              type: str
          description: The network interface attachment.
          returned: always
          type: complex
        description:
          description: The description.
          returned: always
          sample: My interface
          type: str
        groups:
          contains:
            group_id:
              description: The ID of the security group.
              returned: always
              sample: sg-abcdef12
              type: str
            group_name:
              description: The name of the security group.
              returned: always
              sample: mygroup
              type: str
          description: One or more security groups.
          elements: dict
          returned: always
          type: list
        ipv6_addresses:
          contains:
            ipv6_address:
              description: The IPv6 address.
              returned: always
              sample: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
              type: str
          description: One or more IPv6 addresses associated with the network interface.
          elements: dict
          returned: always
          type: list
        mac_address:
          description: The MAC address.
          returned: always
          sample: 00:11:22:33:44:55
          type: str
        network_interface_id:
          description: The ID of the network interface.
          returned: always
          sample: eni-01234567
          type: str
        owner_id:
          description: The AWS account ID of the owner of the network interface.
          returned: always
          sample: 01234567890
          type: str
        private_ip_address:
          description: The IPv4 address of the network interface within the subnet.
          returned: always
          sample: 10.0.0.1
          type: str
        private_ip_addresses:
          contains:
            association:
              contains:
                ip_owner_id:
                  description: The ID of the owner of the Elastic IP address.
                  returned: always
                  sample: amazon
                  type: str
                public_dns_name:
                  description: The public DNS name.
                  returned: always
                  sample: ''
                  type: str
                public_ip:
                  description: The public IP address or Elastic IP address bound to
                    the network interface.
                  returned: always
                  sample: 1.2.3.4
                  type: str
              description: The association information for an Elastic IP address (IPv4)
                associated with the network interface.
              returned: always
              type: complex
            primary:
              description: Indicates whether this IPv4 address is the primary private
                IP address of the network interface.
              returned: always
              sample: true
              type: bool
            private_ip_address:
              description: The private IPv4 address of the network interface.
              returned: always
              sample: 10.0.0.1
              type: str
          description: The private IPv4 addresses associated with the network interface.
          elements: dict
          returned: always
          type: list
        source_dest_check:
          description: Indicates whether source/destination checking is enabled.
          returned: always
          sample: true
          type: bool
        status:
          description: The status of the network interface.
          returned: always
          sample: in-use
          type: str
        subnet_id:
          description: The ID of the subnet for the network interface.
          returned: always
          sample: subnet-0123456
          type: str
        vpc_id:
          description: The ID of the VPC for the network interface.
          returned: always
          sample: vpc-0123456
          type: str
      description: One or more network interfaces for the instance.
      returned: always
      type: complex
    placement:
      contains:
        availability_zone:
          description: The Availability Zone of the instance.
          returned: always
          sample: ap-southeast-2a
          type: str
        group_name:
          description: The name of the placement group the instance is in (for cluster
            compute instances).
          returned: always
          sample: ''
          type: str
        tenancy:
          description: The tenancy of the instance (if the instance is running in
            a VPC).
          returned: always
          sample: default
          type: str
      description: The location where the instance launched, if applicable.
      returned: always
      type: complex
    private_dns_name:
      description: The private DNS name.
      returned: always
      sample: ip-10-0-0-1.ap-southeast-2.compute.internal
      type: str
    private_ip_address:
      description: The IPv4 address of the network interface within the subnet.
      returned: always
      sample: 10.0.0.1
      type: str
    product_codes:
      contains:
        product_code_id:
          description: The product code.
          returned: always
          sample: aw0evgkw8ef3n2498gndfgasdfsd5cce
          type: str
        product_code_type:
          description: The type of product code.
          returned: always
          sample: marketplace
          type: str
      description: One or more product codes.
      elements: dict
      returned: always
      type: list
    public_dns_name:
      description: The public DNS name assigned to the instance.
      returned: always
      sample: null
      type: str
    public_ip_address:
      description: The public IPv4 address assigned to the instance
      returned: always
      sample: 52.0.0.1
      type: str
    root_device_name:
      description: The device name of the root device
      returned: always
      sample: /dev/sda1
      type: str
    root_device_type:
      description: The type of root device used by the AMI.
      returned: always
      sample: ebs
      type: str
    security_groups:
      contains:
        group_id:
          description: The ID of the security group.
          returned: always
          sample: sg-0123456
          type: str
        group_name:
          description: The name of the security group.
          returned: always
          sample: my-security-group
          type: str
      description: One or more security groups for the instance.
      elements: dict
      returned: always
      type: list
    source_dest_check:
      description: Indicates whether source/destination checking is enabled.
      returned: always
      sample: true
      type: bool
    state:
      contains:
        code:
          description: The low byte represents the state.
          returned: always
          sample: 16
          type: int
        name:
          description: The name of the state.
          returned: always
          sample: running
          type: str
      description: The current state of the instance.
      returned: always
      type: complex
    state_transition_reason:
      description: The reason for the most recent state transition.
      returned: always
      sample: null
      type: str
    subnet_id:
      description: The ID of the subnet in which the instance is running.
      returned: always
      sample: subnet-00abcdef
      type: str
    tags:
      description: Any tags assigned to the instance.
      returned: always
      sample: null
      type: dict
    virtualization_type:
      description: The type of virtualization of the AMI.
      returned: always
      sample: hvm
      type: str
    vpc_id:
      description: The ID of the VPC the instance is in.
      returned: always
      sample: vpc-0011223344
      type: dict
  description: a list of ec2 instances
  returned: always
  type: complex