ansible / ansible.builtin / v2.6.0 / module / ec2_metadata_facts Gathers facts (instance metadata) about remote hosts within ec2 | "added in version" 1.0 of ansible.builtin" Authors: Silviu Dicu (@silviud), Vinay Dandekar (@roadmapper) stableinterface | supported by coreansible.builtin.ec2_metadata_facts (v2.6.0) — module
pip
Install with pip install ansible==2.6.0
This module fetches data from the instance metadata endpoint in ec2 as per http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html. The module must be called from within the EC2 instance itself.
# Gather EC2 metadata facts - ec2_metadata_facts:
- debug: msg: "This instance is a t1.micro" when: ansible_ec2_instance_type == "t1.micro"
ansible_facts: contains: ansible_ec2_ami_id: description: The AMI ID used to launch the instance. sample: ami-XXXXXXXX type: string ansible_ec2_ami_launch_index: description: - 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. sample: '0' type: string ansible_ec2_ami_manifest_path: description: - 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. sample: (unknown) type: string ansible_ec2_ancestor_ami_ids: description: - 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. sample: (unknown) type: string ansible_ec2_block_device_mapping_ami: description: The virtual device that contains the root/boot file system. sample: /dev/sda1 type: string ansible_ec2_block_device_mapping_ebsN: description: - 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). sample: /dev/xvdb type: string ansible_ec2_block_device_mapping_ephemeralN: description: The virtual devices associated with ephemeral devices, if any are present. The N indicates the index of the ephemeral volume. sample: /dev/xvdc type: string ansible_ec2_block_device_mapping_root: description: - 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. sample: /dev/sda1 type: string ansible_ec2_block_device_mapping_swap: description: The virtual devices associated with swap. Not always present. sample: /dev/sda2 type: string ansible_ec2_fws_instance_monitoring: description: Value showing whether the customer has enabled detailed one-minute monitoring in CloudWatch. sample: enabled type: string ansible_ec2_hostname: description: - 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). sample: ip-10-0-0-1.ec2.internal type: string ansible_ec2_iam_info: description: - 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. sample: '' type: complex ansible_ec2_iam_info_instanceprofilearn: description: The IAM instance profile ARN. sample: arn:aws:iam::<account id>:instance-profile/<role name> type: string ansible_ec2_iam_info_instanceprofileid: description: IAM instance profile ID. sample: '' type: string ansible_ec2_iam_info_lastupdated: description: IAM info last updated time. sample: '2017-05-12T02:42:27Z' type: string ansible_ec2_iam_instance_profile_role: description: IAM instance role. sample: role_name type: string ansible_ec2_iam_security_credentials_<role name>: description: - 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. sample: '' type: string ansible_ec2_iam_security_credentials_<role name>_accesskeyid: description: IAM role access key ID. sample: '' type: string ansible_ec2_iam_security_credentials_<role name>_code: description: IAM code. sample: Success type: string ansible_ec2_iam_security_credentials_<role name>_expiration: description: IAM role credentials expiration time. sample: '2017-05-12T09:11:41Z' type: string ansible_ec2_iam_security_credentials_<role name>_lastupdated: description: IAM role last updated time. sample: '2017-05-12T02:40:44Z' type: string ansible_ec2_iam_security_credentials_<role name>_secretaccesskey: description: IAM role secret access key. sample: '' type: string ansible_ec2_iam_security_credentials_<role name>_token: description: IAM role token. sample: '' type: string ansible_ec2_iam_security_credentials_<role name>_type: description: IAM role type. sample: AWS-HMAC type: string ansible_ec2_instance_action: description: Notifies the instance that it should reboot in preparation for bundling. sample: none type: string ansible_ec2_instance_id: description: The ID of this instance. sample: i-XXXXXXXXXXXXXXXXX type: string ansible_ec2_instance_identity_document: description: JSON containing instance attributes, such as instance-id, private IP address, etc. sample: '' type: string ansible_ec2_instance_identity_document_accountid: description: '' sample: 012345678901 type: string ansible_ec2_instance_identity_document_architecture: description: Instance system architecture. sample: x86_64 type: string ansible_ec2_instance_identity_document_availabilityzone: description: The Availability Zone in which the instance launched. sample: us-east-1a type: string ansible_ec2_instance_identity_document_billingproducts: description: Billing products for this instance. sample: '' type: string ansible_ec2_instance_identity_document_devpayproductcodes: description: Product codes for the launched AMI. sample: '' type: string ansible_ec2_instance_identity_document_imageid: description: The AMI ID used to launch the instance. sample: ami-01234567 type: string ansible_ec2_instance_identity_document_instanceid: description: The ID of this instance. sample: i-0123456789abcdef0 type: string ansible_ec2_instance_identity_document_instancetype: description: The type of instance. sample: m4.large type: string ansible_ec2_instance_identity_document_kernelid: description: The ID of the kernel launched with this instance, if applicable. sample: '' type: string ansible_ec2_instance_identity_document_pendingtime: description: The instance pending time. sample: '2017-05-11T20:51:20Z' type: string ansible_ec2_instance_identity_document_privateip: description: - 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). sample: 10.0.0.1 type: string ansible_ec2_instance_identity_document_ramdiskid: description: The ID of the RAM disk specified at launch time, if applicable. sample: '' type: string ansible_ec2_instance_identity_document_region: description: The Region in which the instance launched. sample: us-east-1 type: string ansible_ec2_instance_identity_document_version: description: Identity document version. sample: '2010-08-31' type: string ansible_ec2_instance_identity_pkcs7: description: Used to verify the document's authenticity and content against the signature. sample: '' type: string ansible_ec2_instance_identity_rsa2048: description: Used to verify the document's authenticity and content against the signature. sample: '' type: string ansible_ec2_instance_identity_signature: description: Data that can be used by other parties to verify its origin and authenticity. sample: '' type: string ansible_ec2_instance_type: description: The type of instance. sample: m4.large type: string ansible_ec2_local_hostname: description: - 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). sample: ip-10-0-0-1.ec2.internal type: string ansible_ec2_local_ipv4: description: - 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). sample: 10.0.0.1 type: string ansible_ec2_mac: description: - 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). sample: 00:11:22:33:44:55 type: string ansible_ec2_metrics_vhostmd: description: Metrics. sample: '' type: string ansible_ec2_network_interfaces_macs_<mac address>_device_number: description: - 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. sample: '0' type: string ansible_ec2_network_interfaces_macs_<mac address>_interface_id: description: The elastic network interface ID. sample: eni-12345678 type: string ansible_ec2_network_interfaces_macs_<mac address>_ipv4_associations_<ip address>: description: The private IPv4 addresses that are associated with each public-ip address and assigned to that interface. sample: '' type: string ansible_ec2_network_interfaces_macs_<mac address>_ipv6s: description: The IPv6 addresses associated with the interface. Returned only for instances launched into a VPC. sample: '' type: string ansible_ec2_network_interfaces_macs_<mac address>_local_hostname: description: The interface's local hostname. sample: '' type: string ansible_ec2_network_interfaces_macs_<mac address>_local_ipv4s: description: The private IPv4 addresses associated with the interface. sample: '' type: string ansible_ec2_network_interfaces_macs_<mac address>_mac: description: The instance's MAC address. sample: 00:11:22:33:44:55 type: string ansible_ec2_network_interfaces_macs_<mac address>_owner_id: description: - 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. sample: 01234567890 type: string ansible_ec2_network_interfaces_macs_<mac address>_public_hostname: description: - 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. sample: ec2-1-2-3-4.compute-1.amazonaws.com type: string ansible_ec2_network_interfaces_macs_<mac address>_public_ipv4s: description: The Elastic IP addresses associated with the interface. There may be multiple IPv4 addresses on an instance. sample: 1.2.3.4 type: string ansible_ec2_network_interfaces_macs_<mac address>_security_group_ids: description: The IDs of the security groups to which the network interface belongs. Returned only for instances launched into a VPC. sample: sg-01234567,sg-01234568 type: string ansible_ec2_network_interfaces_macs_<mac address>_security_groups: description: Security groups to which the network interface belongs. Returned only for instances launched into a VPC. sample: secgroup1,secgroup2 type: string ansible_ec2_network_interfaces_macs_<mac address>_subnet_id: description: The ID of the subnet in which the interface resides. Returned only for instances launched into a VPC. sample: subnet-01234567 type: string ansible_ec2_network_interfaces_macs_<mac address>_subnet_ipv4_cidr_block: description: The IPv4 CIDR block of the subnet in which the interface resides. Returned only for instances launched into a VPC. sample: 10.0.1.0/24 type: string ansible_ec2_network_interfaces_macs_<mac address>_subnet_ipv6_cidr_blocks: description: The IPv6 CIDR block of the subnet in which the interface resides. Returned only for instances launched into a VPC. sample: '' type: string ansible_ec2_network_interfaces_macs_<mac address>_vpc_id: description: The ID of the VPC in which the interface resides. Returned only for instances launched into a VPC. sample: vpc-0123456 type: string ansible_ec2_network_interfaces_macs_<mac address>_vpc_ipv4_cidr_block: description: The IPv4 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC. sample: 10.0.0.0/16 type: string ansible_ec2_network_interfaces_macs_<mac address>_vpc_ipv4_cidr_blocks: description: The IPv4 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC. sample: 10.0.0.0/16 type: string ansible_ec2_network_interfaces_macs_<mac address>_vpc_ipv6_cidr_blocks: description: The IPv6 CIDR block of the VPC in which the interface resides. Returned only for instances launched into a VPC. sample: '' type: string ansible_ec2_placement_availability_zone: description: The Availability Zone in which the instance launched. sample: us-east-1a type: string ansible_ec2_placement_region: description: The Region in which the instance launched. sample: us-east-1 type: string ansible_ec2_product_codes: description: Product codes associated with the instance, if any. sample: aw0evgkw8e5c1q413zgy5pjce type: string ansible_ec2_profile: description: EC2 instance hardware profile. sample: default-hvm type: string ansible_ec2_public_hostname: description: - 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. sample: ec2-1-2-3-4.compute-1.amazonaws.com type: string ansible_ec2_public_ipv4: description: The public IPv4 address. If an Elastic IP address is associated with the instance, the value returned is the Elastic IP address. sample: 1.2.3.4 type: string ansible_ec2_public_key: description: Public key. Only available if supplied at instance launch time. sample: '' type: string ansible_ec2_ramdisk_id: description: The ID of the RAM disk specified at launch time, if applicable. sample: '' type: string ansible_ec2_reservation_id: description: The ID of the reservation. sample: r-0123456789abcdef0 type: string ansible_ec2_security_groups: description: - 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. sample: securitygroup1,securitygroup2 type: string ansible_ec2_services_domain: description: The domain for AWS resources for the region; for example, amazonaws.com for us-east-1. sample: amazonaws.com type: string ansible_ec2_services_partition: description: - 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. sample: aws type: string ansible_ec2_spot_termination_time: description: - 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. sample: '2015-01-05T18:02:00Z' type: string ansible_ec2_user_data: description: The instance user data. sample: '#!/bin/bash' type: string description: Dictionary of new facts representing discovered properties of the EC2 instance. returned: changed type: complex