steampunk.aws.ec2_instance_info (0.9.0) — module

List EC2 instances

Authors: Manca Bizjak (@mancabizjak), Aljaz Kosir (@aljazkosir), Saso Stanovnik (@sstanovnik), Miha Dolinar (@mdolinar), Tadej Borovsak (@tadeboro)

preview | supported by XLAB Steampunk

Install collection

Install with ansible-galaxy collection install steampunk.aws:==0.9.0


Add to requirements.yml

  collections:
    - name: steampunk.aws
      version: 0.9.0

Description

Retrieve information about AWS EC2 instances.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: List all EC2 instances
  ec2_instance_info:
  register: result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: List a specific EC2 instance
  ec2_instance_info:
    ids: i-0c79884ded545df1a
  register: result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: List several EC2 instances according to their name tag
  ec2_instance_info:
    names:
      - app-server
      - db-server
  register: result

Inputs

    
ami:
    description: ID of the AMI used to launched the instance
    type: str

ids:
    description:
    - Perform the operation for the specified resources.
    elements: str
    type: list

auth:
    description:
    - Parameters for authenticating with the AWS service. Each of them may be defined
      via environment variables.
    suboptions:
      access_key:
        description:
        - The AWS access key ID. If not set, the value of the AWS_ACCESS_KEY environment
          variable will be checked.
        - Mutually exclusive with I(profile).
        required: false
        type: str
      profile:
        description:
        - The name of the AWS profile configured with C(aws configure).
        - Can be used instead of explicitly specifying your access credentials and region.
        - Use C(default) to use the default profile.
        - Mutually exclusive with I(access_key) and I(secret_key).
        required: false
        type: str
      region:
        description:
        - The name of the AWS region.
        - If not set, the value of the AWS_REGION environment variable will be checked.
        - If you set a I(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:
        description:
        - The AWS secret access key. If not set, the value of the AWS_SECRET_KEY environment
          variable will be checked.
        - Mutually exclusive with I(profile).
        required: false
        type: str
      url:
        description:
        - 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.
        required: false
        type: str
    type: dict

type:
    description: Type of the EC2 instance.
    type: str

names:
    description:
    - Limit the results to the resources with specified names.
    elements: str
    type: list

states:
    default:
    - pending
    - running
    - stopping
    - stopped
    - shutting-down
    description:
    - Limit the results to EC2 instances in the specified states.
    - By default, the module includes instances in all states except C(terminated).
    - This parameter cannot contain C(terminated), as terminated instances are treated
      as absent.
    elements: str
    type: list

subnet:
    description: ID of the subnet where the instance is running.
    type: str

filters:
    description:
    - 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, I(any)
      value must match for the AWS resource to be included.
    - When multiple filters are provided, the result contains AWS resources matching I(all)
      of them.
    - If a filter is specified in C(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 C(filters), the top-level parameter
      has precedence.
    type: dict

Outputs

object:
  contains:
    ami:
      description: ID of the AMI used to launched the instance.
      returned: always
      sample: ami-0343ab73df9eb1496
      type: str
    availability_zone:
      description: ID of the availability zone for the instance.
      returned: always
      sample: az-use-1
      type: str
    id:
      description: ID of the EC2 instance.
      returned: always
      sample: i-841b9271gd
      type: str
    key_pair:
      description: Name of the key pair to be used when connecting to the instance.
      returned: always
      sample: my-key-pair
      type: str
    launched_at:
      description: The time when instance was launched.
      returned: always
      sample: '2020-04-15T08:08:40+00:00'
      type: str
    monitoring:
      description: CloudWatch monitoring mode for the instance.
      returned: always
      sample: detailed
      type: str
    network_interface:
      description: ID of the instance's primary network interface.
      returned: always
      sample: eni-2dfr38df335
      type: str
    on_instance_initiated_shutdown:
      description: The behavior when shut down is initiated from the instance.
      returned: always
      sample: terminate
      type: str
    secondary_network_interfaces:
      description: IDs of the secondary network interfaces attached to the instance.
      returned: always
      sample: []
      type: list
    security_groups:
      description: IDs of security groups associated with the instance.
      returned: always
      sample:
      - sg-27fhs72gs922f
      type: list
    state:
      description: State of the EC2 instance as reported by AWS.
      returned: always
      sample: running
      type: str
    subnet:
      description: ID of the subnet containing the instance.
      returned: always
      sample: subnet-14hs85ns83hg
      type: str
    tenancy:
      description: The instance tenancy setting.
      returned: always
      sample: default
      type: str
    type:
      description: EC2 instance type.
      returned: always
      sample: a1.xsmall
      type: str
    vpc:
      description: ID of the VPC containing the instance.
      returned: always
      sample: vpc-129385ns2s2
      type: str
  description:
  - An object representing the EC2 Instance.
  returned: success
  type: complex

See also