Documentation

ali_instance_facts - Gather facts on instances of Alibaba Cloud ECS.

New in version 2.8.

Synopsis

  • This module fetches data from the Open API in Alicloud. The module must be called from within the ECS instance itself.

Requirements

The below requirements are needed on the host that executes this module.

  • footmark >= 1.7.0
  • python >= 2.6

Parameters

Parameter Choices/Defaults Comments
alicloud_access_key
Aliyun Cloud access key. If not set then the value of environment variable ALICLOUD_ACCESS_KEY, ALICLOUD_ACCESS_KEY_ID will be used instead.

aliases: access_key_id, access_key
alicloud_region
The Aliyun Cloud region to use. If not specified then the value of environment variable ALICLOUD_REGION, ALICLOUD_REGION_ID will be used instead.

aliases: region, region_id
alicloud_secret_key
Aliyun Cloud secret key. If not set then the value of environment variable ALICLOUD_SECRET_KEY, ALICLOUD_SECRET_ACCESS_KEY will be used instead.

aliases: secret_access_key, secret_key
alicloud_security_token
The Aliyun Cloud security token. If not specified then the value of environment variable ALICLOUD_SECURITY_TOKEN will be used instead.

aliases: security_token
availability_zone
(Deprecated) Aliyun availability zone ID in which to launch the instance. Please use filter item 'zone_id' instead.

aliases: alicloud_zone
filters
A dict of filters to apply. Each dict item consists of a filter key and a filter value. The filter keys can be all of request parameters. See https://www.alibabacloud.com/help/doc-detail/25506.htm for parameter details. Filter keys can be same as request parameter name or be lower case and use underscore ("_") or dash ("-") to connect different words in one parameter. 'InstanceIds' should be a list and it will be appended to instance_ids automatically. 'Tag.n.Key' and 'Tag.n.Value' should be a dict and using tags instead.
instance_ids
A list of ECS instance ids.

aliases: ids
instance_names
(Deprecated) A list of ECS instance names. Please use filter item 'instance_name' instead.

aliases: names
name_prefix
Use a instance name prefix to filter ecs instances.
tags
A hash/dictionaries of instance tags. {"key":"value"}

aliases: instance_tags

Notes

Note

  • If parameters are not set within the module, the following environment variables can be used in decreasing order of precedence ALICLOUD_ACCESS_KEY or ALICLOUD_ACCESS_KEY_ID, ALICLOUD_SECRET_KEY or ALICLOUD_SECRET_ACCESS_KEY, ALICLOUD_REGION or ALICLOUD_REGION_ID, ALICLOUD_SECURITY_TOKEN
  • ALICLOUD_REGION or ALICLOUD_REGION_ID can be typically be used to specify the ALICLOUD region, when required, but this can also be configured in the footmark config file

Examples

# Fetch instances details according to setting different filters
- name: fetch instances details example
  hosts: localhost
  vars:
    alicloud_access_key: <your-alicloud-access-key>
    alicloud_secret_key: <your-alicloud-secret-key>
    alicloud_region: cn-beijing
    availability_zone: cn-beijing-a

  tasks:
    - name: Find all instances in the specified region
      ali_instance_facts:
      register: all_instances
    - name: Find all instances based on the specified ids
      ali_instance_facts:
        instance_ids:
          - "i-35b333d9"
          - "i-ddav43kd"
      register: instances_by_ids
    - name: Find all instances based on the specified name_prefix
      ali_instance_facts:
        name_prefix: "ecs_instance_"
      register: instances_by_name_prefix

Return Values

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

Key Returned Description
ids
list
always
List of ECS instance IDs

Sample:
['i-12345er', 'i-3245fs']
instances
complex
always
List of ECS instances

  resource_group_id
string
always
The id of the resource group to which the instance belongs.

Sample:
my-ecs-group
  availability_zone
string
always
The availability zone of the instance is in.

Sample:
cn-beijing-a
  internet_max_bandwidth_out
int
always
Maximum incoming bandwidth from the internet network.

Sample:
20
  instance_type_family
string
always
The instance type family of the instance belongs.

Sample:
ecs.sn1ne
  creation_time
string
always
The time the instance was created.

Sample:
2018-06-25T04:08Z
  id
string
always
Alias of instance_id.

Sample:
i-abc12345
  security_groups
complex
always
One or more security groups for the instance.

    group_id
string
always
The ID of the security group.

Sample:
sg-0123456
  description
string
always
The instance description.

Sample:
my ansible instance
  instance_id
string
always
ECS instance resource ID.

Sample:
i-abc12345
  io_optimized
bool
always
Indicates whether the instance is optimized for EBS I/O.

  ostype
string
always
The operation system type of the instance owned.

Sample:
linux
  expired_time
string
always
The time the instance will expire.

Sample:
2099-12-31T15:59Z
  memory
int
always
Memory size of the instance.

Sample:
8192
  gpu
complex
always
The attribution of instane GPU.

    amount
int
always
The count of the GPU.

    spec
string
always
The specification of the GPU.

  status
string
always
The current status of the instance.

Sample:
running
  internet_charge_type
string
always
The billing method of the network bandwidth.

Sample:
PayByBandwidth
  tags
dict
always
Any tags assigned to the instance.

  public_ip_address
string
always
The public IPv4 address assigned to the instance or eip address

Sample:
43.0.0.1
  osname
string
always
The operation system name of the instance owned.

Sample:
CentOS
  image_id
string
always
The ID of the image used to launch the instance.

Sample:
m-0011223344
  block_device_mappings
complex
always
Any block device mapping entries for the instance.

    status
string
always
The attachment state.

Sample:
in_use
    device_name
string
always
The device name exposed to the instance (for example, /dev/xvda).

Sample:
/dev/xvda
    delete_on_termination
bool
always
Indicates whether the volume is deleted on instance termination.

Sample:
True
    attach_time
string
always
The time stamp when the attachment initiated.

Sample:
2018-06-25T04:08:26Z
    volume_id
string
always
The ID of the cloud disk.

Sample:
d-2zei53pjsi117y6gf9t6
  eip
complex
always
The attribution of EIP associated with the instance.

    ip_address
string
always
EIP address.

Sample:
42.10.2.2
    internet_charge_type
string
always
The internet charge type of the EIP.

Sample:
paybybandwidth
    allocation_id
string
always
The ID of the EIP.

Sample:
eip-12345
  network_interfaces
complex
always
One or more network interfaces for the instance.

    network_interface_id
string
always
The ID of the network interface.

Sample:
eni-01234567
    primary_ip_address
string
always
The primary IPv4 address of the network interface within the vswitch.

Sample:
10.0.0.1
    mac_address
string
always
The MAC address.

Sample:
00:11:22:33:44:55
  internet_max_bandwidth_in
int
always
Maximum incoming bandwidth from the internet network.

Sample:
200
  instance_name
string
always
The name of the instance.

Sample:
my-ecs
  instance_type
string
always
The instance type of the running instance.

Sample:
ecs.sn1ne.xlarge
  host_name
string
always
The host name of the instance.

Sample:
iZ2zewaoZ
  private_ip_address
string
always
The IPv4 address of the network interface within the subnet.

Sample:
10.0.0.1
  vpc_id
dict
always
The ID of the VPC the instance is in.

Sample:
vpc-0011223344
  instance_charge_type
string
always
The instance charge type.

Sample:
PostPaid
  vswitch_id
string
always
The ID of the vswitch in which the instance is running.

Sample:
vsw-dew00abcdef
  cpu
int
always
The CPU core count of the instance.

Sample:
4


Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Author

  • He Guimin (@xiaozhu36)

Hint

If you notice any issues in this documentation you can edit this document to improve it.