amazon.aws.ec2_metadata_facts module – Gathers facts (instance metadata) about remote hosts within EC2
Note
This module is part of the amazon.aws collection (version 5.5.1).
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_metadata_facts
.
New in amazon.aws 1.0.0
Synopsis
This module fetches data from the instance metadata endpoint in EC2 as per https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html.
The module must be called from within the EC2 instance itself.
The module is configured to utilize the session oriented Instance Metadata Service v2 (IMDSv2) https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html.
If the HttpEndpoint parameter https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyInstanceMetadataOptions.html#API_ModifyInstanceMetadataOptions_RequestParameters is set to disabled for the EC2 instance, the module will return an error while retrieving a session token.
Notes
Note
Parameters to filter on ec2_metadata_facts may be added later.
Examples
# Gather EC2 metadata facts
- amazon.aws.ec2_metadata_facts:
- debug:
msg: "This instance is a t1.micro"
when: ansible_ec2_instance_type == "t1.micro"
Returned Facts
Facts returned by this module are added/updated in the hostvars
host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.
Key |
Description |
---|---|
The AMI ID used to launch the instance. Returned: success Sample: |
|
If you started more than one instance at the same time, this value indicates the order in which the instance was launched. The value of the first instance launched is 0. Returned: success Sample: |
|
The path to the AMI manifest file in Amazon S3. If you used an Amazon EBS-backed AMI to launch the instance, the returned result is unknown. Returned: success Sample: |
|
The AMI IDs of any instances that were rebundled to create this AMI. This value will only exist if the AMI manifest file contained an ancestor-amis key. Returned: success Sample: |
|
The virtual device that contains the root/boot file system. Returned: success Sample: |
|
The virtual devices associated with Amazon EBS volumes, if any are present. Amazon EBS volumes are only available in metadata if they were present at launch time or when the instance was last started. The N indicates the index of the Amazon EBS volume (such as ebs1 or ebs2). Returned: success Sample: |
|
The virtual devices associated with ephemeral devices, if any are present. The N indicates the index of the ephemeral volume. Returned: success Sample: |
|
The virtual devices or partitions associated with the root devices, or partitions on the virtual device, where the root (/ or C) file system is associated with the given instance. Returned: success Sample: |
|
The virtual devices associated with swap. Not always present. Returned: success Sample: |
|
Value showing whether the customer has enabled detailed one-minute monitoring in CloudWatch. Returned: success Sample: |
|
The private IPv4 DNS hostname of the instance. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which the device number is 0). Returned: success Sample: |
|
If there is an IAM role associated with the instance, contains information about the last time the instance profile was updated, including the instance’s LastUpdated date, InstanceProfileArn, and InstanceProfileId. Otherwise, not present. Returned: success Sample: |
|
The ARN of the InstanceProfile associated with the Instance. Returned: success |
|
The Id of the InstanceProfile associated with the Instance. Returned: success |
|
The last time which InstanceProfile is associated with the Instance changed. Returned: success |
|
The IAM instance profile ARN. Returned: success Sample: |
|
IAM instance profile ID. Returned: success Sample: |
|
IAM info last updated time. Returned: success Sample: |
|
IAM instance role. Returned: success Sample: |
|
If there is an IAM role associated with the instance, role-name is the name of the role, and role-name contains the temporary security credentials associated with the role. Otherwise, not present. Returned: success Sample: |
|
IAM role access key ID. Returned: success Sample: |
|
IAM code. Returned: success Sample: |
|
IAM role credentials expiration time. Returned: success Sample: |
|
IAM role last updated time. Returned: success Sample: |
|
IAM role secret access key. Returned: success Sample: |
|
IAM role token. Returned: success Sample: |
|
IAM role type. Returned: success Sample: |
|
Notifies the instance that it should reboot in preparation for bundling. Returned: success Sample: |
|
The ID of this instance. Returned: success Sample: |
|
JSON containing instance attributes, such as instance-id, private IP address, etc. Returned: success Sample: |
|
Returned: success Sample: |
|
Instance system architecture. Returned: success Sample: |
|
The Availability Zone in which the instance launched. Returned: success Sample: |
|
Billing products for this instance. Returned: success Sample: |
|
Product codes for the launched AMI. Returned: success Sample: |
|
The AMI ID used to launch the instance. Returned: success Sample: |
|
The ID of this instance. Returned: success Sample: |
|
The type of instance. Returned: success Sample: |
|
The ID of the kernel launched with this instance, if applicable. Returned: success Sample: |
|
The instance pending time. Returned: success Sample: |
|
The private IPv4 address of the instance. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which the device number is 0). Returned: success Sample: |
|
The ID of the RAM disk specified at launch time, if applicable. Returned: success Sample: |
|
The Region in which the instance launched. Returned: success Sample: |
|
Identity document version. Returned: success Sample: |
|
Used to verify the document’s authenticity and content against the signature. Returned: success Sample: |
|
Used to verify the document’s authenticity and content against the signature. Returned: success Sample: |
|
Data that can be used by other parties to verify its origin and authenticity. Returned: success Sample: |
|
The purchasing option of the instance. Returned: success Sample: |
|
The list of tags keys of the instance. Returns empty list if access to tags (InstanceMetadataTags) in instance metadata is not enabled. Returned: success Sample: |
|
The type of the instance. Returned: success Sample: |
|
The private IPv4 DNS hostname of the instance. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which the device number is 0). Returned: success Sample: |
|
The private IPv4 address of the instance. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which the device number is 0). Returned: success Sample: |
|
The instance’s media access control (MAC) address. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which the device number is 0). Returned: success Sample: |
|
Metrics; no longer available. Returned: success Sample: |
|
The unique device number associated with that interface. The device number corresponds to the device name; for example, a device-number of 2 is for the eth2 device. This category corresponds to the DeviceIndex and device-index fields that are used by the Amazon EC2 API and the EC2 commands for the AWS CLI. Returned: success Sample: |
|
The elastic network interface ID. Returned: success Sample: |
|
The private IPv4 addresses that are associated with each public-ip address and assigned to that interface. Returned: success Sample: |
|
The IPv6 addresses associated with the interface. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The interface’s local hostname. Returned: success Sample: |
|
The private IPv4 addresses associated with the interface. Returned: success Sample: |
|
The instance’s MAC address. Returned: success Sample: |
|
The ID of the owner of the network interface. In multiple-interface environments, an interface can be attached by a third party, such as Elastic Load Balancing. Traffic on an interface is always billed to the interface owner. Returned: success Sample: |
|
The interface’s public DNS (IPv4). If the instance is in a VPC, this category is only returned if the enableDnsHostnames attribute is set to true. Returned: success Sample: |
|
The Elastic IP addresses associated with the interface. There may be multiple IPv4 addresses on an instance. Returned: success Sample: |
|
The IDs of the security groups to which the network interface belongs. Returned only for instances launched into a VPC. Returned: success Sample: |
|
Security groups to which the network interface belongs. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The ID of the subnet in which the interface resides. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The IPv4 CIDR block of the subnet in which the interface resides. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The IPv6 CIDR block of the subnet in which the interface resides. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The ID of the VPC in which the interface resides. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The IPv4 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The IPv4 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The IPv6 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC. Returned: success Sample: |
|
The Availability Zone in which the instance launched. Returned: success Sample: |
|
The Region in which the instance launched. Returned: success Sample: |
|
Product codes associated with the instance, if any. Returned: success Sample: |
|
EC2 instance hardware profile. Returned: success Sample: |
|
The instance’s public DNS. If the instance is in a VPC, this category is only returned if the enableDnsHostnames attribute is set to true. Returned: success Sample: |
|
The public IPv4 address. If an Elastic IP address is associated with the instance, the value returned is the Elastic IP address. Returned: success Sample: |
|
Public key. Only available if supplied at instance launch time. Returned: success Sample: |
|
The ID of the RAM disk specified at launch time, if applicable. Returned: success Sample: |
|
The ID of the reservation. Returned: success Sample: |
|
The names of the security groups applied to the instance. After launch, you can only change the security groups of instances running in a VPC. Such changes are reflected here and in network/interfaces/macs/mac/security-groups. Returned: success Sample: |
|
The domain for AWS resources for the region; for example, amazonaws.com for us-east-1. Returned: success Sample: |
|
The partition that the resource is in. For standard AWS regions, the partition is aws. If you have resources in other partitions, the partition is aws-partitionname. For example, the partition for resources in the China (Beijing) region is aws-cn. Returned: success Sample: |
|
The approximate time, in UTC, that the operating system for your Spot instance will receive the shutdown signal. This item is present and contains a time value only if the Spot instance has been marked for termination by Amazon EC2. The termination-time item is not set to a time if you terminated the Spot instance yourself. Returned: success Sample: |
|
The instance user data. Returned: success Sample: |