ec2_metadata_facts - Gathers facts (instance metadata) about remote hosts within ec2

Synopsis

Examples

# Gather EC2 metadata facts
- ec2_metadata_facts:

- debug:
    msg: "This instance is a t1.micro"
  when: ansible_ec2_instance_type == "t1.micro"

Return Values

Common return values are documented here Return Values, the following are the fields unique to this module:

name description returned type sample
ansible_facts
Dictionary of new facts representing discovered properties of the EC2 instance.
changed complex
contains:
name description returned type sample
ansible_ec2_ami_launch_index
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.
string 0
ansible_ec2_services_partition
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.
string aws
ansible_ec2_iam_security_credentials__accesskeyid
IAM role access key ID.
string
ansible_ec2_iam_security_credentials__lastupdated
IAM role last updated time.
string 2017-05-12T02:40:44Z
ansible_ec2_spot_termination_time
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.
string 2015-01-05T18:02:00Z
ansible_ec2_iam_instance_profile_role
IAM instance role.
string role_name
ansible_ec2_security_groups
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.
string securitygroup1,securitygroup2
ansible_ec2_network_interfaces_macs__vpc_id
The ID of the VPC in which the interface resides. Returned only for instances launched into a VPC.
string vpc-0123456
ansible_ec2_network_interfaces_macs__public_ipv4s
The Elastic IP addresses associated with the interface. There may be multiple IPv4 addresses on an instance.
string 1.2.3.4
ansible_ec2_instance_identity_document_ramdiskid
The ID of the RAM disk specified at launch time, if applicable.
string
ansible_ec2_profile
EC2 instance hardware profile.
string default-hvm
ansible_ec2_network_interfaces_macs__vpc_ipv4_cidr_blocks
The IPv4 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC.
string 10.0.0.0/16
ansible_ec2_placement_region
The Region in which the instance launched.
string us-east-1
ansible_ec2_ami_id
The AMI ID used to launch the instance.
string ami-XXXXXXXX
ansible_ec2_reservation_id
The ID of the reservation.
string r-0123456789abcdef0
ansible_ec2_block_device_mapping_root
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.
string /dev/sda1
ansible_ec2_instance_identity_document_kernelid
The ID of the kernel launched with this instance, if applicable.
string
ansible_ec2_instance_identity_document_instanceid
The ID of this instance.
string i-0123456789abcdef0
ansible_ec2_local_hostname
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).
string ip-10-0-0-1.ec2.internal
ansible_ec2_block_device_mapping_swap
The virtual devices associated with swap. Not always present.
string /dev/sda2
ansible_ec2_placement_availability_zone
The Availability Zone in which the instance launched.
string us-east-1a
ansible_ec2_network_interfaces_macs__owner_id
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.
string 01234567890
ansible_ec2_instance_identity_document_accountid string 012345678901
ansible_ec2_hostname
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).
string ip-10-0-0-1.ec2.internal
ansible_ec2_network_interfaces_macs__security_groups
Security groups to which the network interface belongs. Returned only for instances launched into a VPC.
string secgroup1,secgroup2
ansible_ec2_iam_info_instanceprofileid
IAM instance profile ID.
string
ansible_ec2_network_interfaces_macs__subnet_ipv6_cidr_blocks
The IPv6 CIDR block of the subnet in which the interface resides. Returned only for instances launched into a VPC.
string
ansible_ec2_instance_identity_signature
Data that can be used by other parties to verify its origin and authenticity.
string
ansible_ec2_instance_identity_document
JSON containing instance attributes, such as instance-id, private IP address, etc.
string
ansible_ec2_fws_instance_monitoring
Value showing whether the customer has enabled detailed one-minute monitoring in CloudWatch.
string enabled
ansible_ec2_public_ipv4
The public IPv4 address. If an Elastic IP address is associated with the instance, the value returned is the Elastic IP address.
string 1.2.3.4
ansible_ec2_iam_info_lastupdated
IAM info last updated time.
string 2017-05-12T02:42:27Z
ansible_ec2_network_interfaces_macs__vpc_ipv4_cidr_block
The IPv4 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC.
string 10.0.0.0/16
ansible_ec2_public_hostname
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.
string ec2-1-2-3-4.compute-1.amazonaws.com
ansible_ec2_network_interfaces_macs__local_ipv4s
The private IPv4 addresses associated with the interface.
string
ansible_ec2_instance_identity_document_version
Identity document version.
string 2010-08-31
ansible_ec2_instance_identity_document_pendingtime
The instance pending time.
string 2017-05-11T20:51:20Z
ansible_ec2_network_interfaces_macs__ipv6s
The IPv6 addresses associated with the interface. Returned only for instances launched into a VPC.
string
ansible_ec2_iam_info_instanceprofilearn
The IAM instance profile ARN.
string arn:aws:iam:::instance-profile/
ansible_ec2_services_domain
The domain for AWS resources for the region; for example, amazonaws.com for us-east-1.
string amazonaws.com
ansible_ec2_instance_identity_document_privateip
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).
string 10.0.0.1
ansible_ec2_ramdisk_id
The ID of the RAM disk specified at launch time, if applicable.
string
ansible_ec2_iam_security_credentials__type
IAM role type.
string AWS-HMAC
ansible_ec2_user_data
The instance user data.
string #!/bin/bash
ansible_ec2_iam_info
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.
complex
ansible_ec2_iam_security_credentials__code
IAM code.
string Success
ansible_ec2_block_device_mapping_ami
The virtual device that contains the root/boot file system.
string /dev/sda1
ansible_ec2_instance_identity_document_availabilityzone
The Availability Zone in which the instance launched.
string us-east-1a
ansible_ec2_instance_identity_document_region
The Region in which the instance launched.
string us-east-1
ansible_ec2_ami_manifest_path
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.
string (unknown)
ansible_ec2_local_ipv4
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).
string 10.0.0.1
ansible_ec2_instance_action
Notifies the instance that it should reboot in preparation for bundling.
string none
ansible_ec2_network_interfaces_macs__interface_id
The elastic network interface ID.
string eni-12345678
ansible_ec2_iam_security_credentials__expiration
IAM role credentials expiration time.
string 2017-05-12T09:11:41Z
ansible_ec2_network_interfaces_macs__security_group_ids
The IDs of the security groups to which the network interface belongs. Returned only for instances launched into a VPC.
string sg-01234567,sg-01234568
ansible_ec2_network_interfaces_macs__vpc_ipv6_cidr_blocks
The IPv6 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC.
string
ansible_ec2_iam_security_credentials__secretaccesskey
IAM role secret access key.
string
ansible_ec2_instance_identity_document_devpayproductcodes
Product codes for the launched AMI.
string
ansible_ec2_block_device_mapping_ebsN
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).
string /dev/xvdb
ansible_ec2_network_interfaces_macs__mac
The instance's MAC address.
string 00:11:22:33:44:55
ansible_ec2_instance_identity_document_billingproducts
Billing products for this instance.
string
ansible_ec2_iam_security_credentials__token
IAM role token.
string
ansible_ec2_instance_identity_document_architecture
Instance system architecture.
string x86_64
ansible_ec2_public_key
Public key. Only available if supplied at instance launch time.
string
ansible_ec2_network_interfaces_macs__ipv4_associations_
The private IPv4 addresses that are associated with each public-ip address and assigned to that interface.
string
ansible_ec2_ancestor_ami_ids
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.
string (unknown)
ansible_ec2_instance_identity_pkcs7
Used to verify the document's authenticity and content against the signature.
string
ansible_ec2_network_interfaces_macs__public_hostname
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.
string ec2-1-2-3-4.compute-1.amazonaws.com
ansible_ec2_instance_id
The ID of this instance.
string i-XXXXXXXXXXXXXXXXX
ansible_ec2_mac
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).
string 00:11:22:33:44:55
ansible_ec2_instance_identity_document_imageid
The AMI ID used to launch the instance.
string ami-01234567
ansible_ec2_iam_security_credentials_
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.
string
ansible_ec2_network_interfaces_macs__device_number
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.
string 0
ansible_ec2_instance_type
The type of instance.
string m4.large
ansible_ec2_metrics_vhostmd
Metrics.
string
ansible_ec2_network_interfaces_macs__subnet_id
The ID of the subnet in which the interface resides. Returned only for instances launched into a VPC.
string subnet-01234567
ansible_ec2_network_interfaces_macs__local_hostname
The interface's local hostname.
string
ansible_ec2_network_interfaces_macs__subnet_ipv4_cidr_block
The IPv4 CIDR block of the subnet in which the interface resides. Returned only for instances launched into a VPC.
string 10.0.1.0/24
ansible_ec2_product_codes
Product codes associated with the instance, if any.
string aw0evgkw8e5c1q413zgy5pjce
ansible_ec2_instance_identity_rsa2048
Used to verify the document's authenticity and content against the signature.
string
ansible_ec2_instance_identity_document_instancetype
The type of instance.
string m4.large
ansible_ec2_block_device_mapping_ephemeralN
The virtual devices associated with ephemeral devices, if any are present. The N indicates the index of the ephemeral volume.
string /dev/xvdc

Notes

Note

  • Parameters to filter on ec2_metadata_facts may be added later.

Status

This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.

Maintenance Info

For more information about Red Hat’s this support of this module, please refer to this knowledge base article<https://access.redhat.com/articles/rhel-top-support-policies>

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.4/ec2_metadata_facts_module.html