community / community.general / 8.5.0 / module / ali_instance Create, Start, Stop, Restart or Terminate an Instance in ECS; Add or Remove Instance to/from a Security Group Authors: He Guimin (@xiaozhu36)community.general.ali_instance (8.5.0) — module
Install with ansible-galaxy collection install community.general:==8.5.0
collections: - name: community.general version: 8.5.0
Create, start, stop, restart, modify or terminate ecs instances.
Add or remove ecs instances to/from security group.
# basic provisioning example vpc network - name: Basic provisioning example hosts: localhost vars: alicloud_access_key: <your-alicloud-access-key-id> alicloud_secret_key: <your-alicloud-access-secret-key> alicloud_region: cn-beijing image: ubuntu1404_64_40G_cloudinit_20160727.raw instance_type: ecs.n4.small vswitch_id: vsw-abcd1234 assign_public_ip: true max_bandwidth_out: 10 host_name: myhost password: mypassword system_disk_category: cloud_efficiency system_disk_size: 100 internet_charge_type: PayByBandwidth security_groups: ["sg-f2rwnfh23r"] instance_ids: ["i-abcd12346", "i-abcd12345"] force: true tasks: - name: Launch ECS instance in VPC network community.general.ali_instance: alicloud_access_key: '{{ alicloud_access_key }}' alicloud_secret_key: '{{ alicloud_secret_key }}' alicloud_region: '{{ alicloud_region }}' image: '{{ image }}' system_disk_category: '{{ system_disk_category }}' system_disk_size: '{{ system_disk_size }}' instance_type: '{{ instance_type }}' vswitch_id: '{{ vswitch_id }}' assign_public_ip: '{{ assign_public_ip }}' internet_charge_type: '{{ internet_charge_type }}' max_bandwidth_out: '{{ max_bandwidth_out }}' tags: Name: created_one host_name: '{{ host_name }}' password: '{{ password }}' - name: With count and count_tag to create a number of instances community.general.ali_instance: alicloud_access_key: '{{ alicloud_access_key }}' alicloud_secret_key: '{{ alicloud_secret_key }}' alicloud_region: '{{ alicloud_region }}' image: '{{ image }}' system_disk_category: '{{ system_disk_category }}' system_disk_size: '{{ system_disk_size }}' instance_type: '{{ instance_type }}' assign_public_ip: '{{ assign_public_ip }}' security_groups: '{{ security_groups }}' internet_charge_type: '{{ internet_charge_type }}' max_bandwidth_out: '{{ max_bandwidth_out }}' tags: Name: created_one Version: 0.1 count: 2 count_tag: Name: created_one host_name: '{{ host_name }}' password: '{{ password }}' - name: Start instance community.general.ali_instance: alicloud_access_key: '{{ alicloud_access_key }}' alicloud_secret_key: '{{ alicloud_secret_key }}' alicloud_region: '{{ alicloud_region }}' instance_ids: '{{ instance_ids }}' state: 'running' - name: Reboot instance forcibly ecs: alicloud_access_key: '{{ alicloud_access_key }}' alicloud_secret_key: '{{ alicloud_secret_key }}' alicloud_region: '{{ alicloud_region }}' instance_ids: '{{ instance_ids }}' state: 'restarted' force: '{{ force }}' - name: Add instances to an security group ecs: alicloud_access_key: '{{ alicloud_access_key }}' alicloud_secret_key: '{{ alicloud_secret_key }}' alicloud_region: '{{ alicloud_region }}' instance_ids: '{{ instance_ids }}' security_groups: '{{ security_groups }}'
tags: aliases: - instance_tags description: - A hash/dictionaries of instance tags, to add to the new instance or for starting/stopping instance by tag. V({"key":"value"}) type: dict version_added: 0.2.0 version_added_collection: community.general count: default: 1 description: - The number of the new instance. An integer value which indicates how many instances that match O(count_tag) should be running. Instances are either created or terminated based on this value. type: int force: default: false description: - Whether the current operation needs to be execute forcibly. type: bool state: choices: - present - running - stopped - restarted - absent default: present description: - The state of the instance after operating. type: str period: default: 1 description: - The charge duration of the instance, in months. Required when O(instance_charge_type=PrePaid). - The valid value are [1-9, 12, 24, 36]. type: int dry_run: default: false description: - Specifies whether to send a dry-run request. - If O(dry_run=true), Only a dry-run request is sent and no instance is created. The system checks whether the required parameters are set, and validates the request format, service permissions, and available ECS instances. If the validation fails, the corresponding error code is returned. If the validation succeeds, the DryRunOperation error code is returned. - If O(dry_run=false), A request is sent. If the validation succeeds, the instance is created. type: bool version_added: 0.2.0 version_added_collection: community.general profile: description: - This is the Alicloud profile name as set in the shared credentials file. It can also be sourced from the E(ALICLOUD_PROFILE) environment variable. type: str image_id: aliases: - image description: - Image ID used to launch instances. Required when O(state=present) and creating new ECS instances. type: str key_name: aliases: - keypair description: - The name of key pair which is used to access ECS instance in SSH. required: false type: str password: description: - The password to login instance. After rebooting instances, modified password will take effect. type: str count_tag: description: - O(count) determines how many instances based on a specific tag criteria should be present. This can be expressed in multiple ways and is shown in the EXAMPLES section. The specified count_tag must already exist or be passed in as the O(tags) option. If it is not specified, it will be replaced by O(instance_name). type: str host_name: description: - Instance host name. Ordered hostname is not supported. type: str user_data: description: - User-defined data to customize the startup behaviors of an ECS instance and to pass data into an ECS instance. It only will take effect when launching the new ECS instances. required: false type: str auto_renew: default: false description: - Whether automate renew the charge of the instance. type: bool purge_tags: default: false description: - Delete any tags not specified in the task that are on the instance. If True, it means you have to specify all the desired tags on each task affecting an instance. type: bool version_added: 0.2.0 version_added_collection: community.general vswitch_id: aliases: - subnet_id description: - The subnet ID in which to launch the instances (VPC). type: str description: description: - The description of ECS instance, which is a string of 2 to 256 characters. It cannot begin with http:// or https://. type: str period_unit: choices: - Month - Week default: Month description: - The duration unit that you will buy the resource. It is valid when O(instance_charge_type=PrePaid). type: str version_added: 0.2.0 version_added_collection: community.general instance_ids: description: - A list of instance ids. It is required when need to operate existing instances. If it is specified, O(count) will lose efficacy. elements: str type: list ecs_role_name: aliases: - role_name description: - The RAM Role Name attached on a ECS instance for API operations. You can retrieve this from the 'Access Control' section of the Alibaba Cloud console. - If you're running Ansible from an ECS instance with RAM Instance using RAM Role, Ansible will just access the metadata U(http://100.100.100.200/latest/meta-data/ram/security-credentials/<ecs_role_name>) to obtain the STS credential. This is a preferred approach over any other when running in ECS as you can avoid hard coding credentials. Instead these are leased on-the-fly by Ansible which reduces the chance of leakage. type: str instance_name: aliases: - name description: - The name of ECS instance, which is a string of 2 to 128 Chinese or English characters. It must begin with an uppercase/lowercase letter or a Chinese character and can contain numerals, ".", "_" or "-". It cannot begin with http:// or https://. type: str instance_type: aliases: - type description: - Instance type used to launch instances. Required when O(state=present) and creating new ECS instances. type: str ram_role_name: description: - The name of the instance RAM role. type: str version_added: 0.2.0 version_added_collection: community.general spot_strategy: choices: - NoSpot - SpotWithPriceLimit - SpotAsPriceGo default: NoSpot description: - The bidding mode of the pay-as-you-go instance. This parameter is valid when InstanceChargeType is set to PostPaid. type: str version_added: 0.2.0 version_added_collection: community.general unique_suffix: default: false description: - Specifies whether to add sequential suffixes to the host_name. The sequential suffix ranges from 001 to 999. type: bool version_added: 0.2.0 version_added_collection: community.general alicloud_region: aliases: - region - region_id description: - The Alibaba Cloud region to use. If not specified then the value of environment variable E(ALICLOUD_REGION), E(ALICLOUD_REGION_ID) will be used instead. required: true type: str security_groups: aliases: - group_ids description: - A list of security group IDs. elements: str type: list max_bandwidth_in: default: 200 description: - Maximum incoming bandwidth from the public network, measured in Mbps (Megabits per second). type: int spot_price_limit: description: - The maximum hourly price for the preemptible instance. This parameter supports a maximum of three decimal places and takes effect when the SpotStrategy parameter is set to SpotWithPriceLimit. type: float version_added: 0.2.0 version_added_collection: community.general system_disk_name: description: - Name of the system disk. type: str system_disk_size: default: 40 description: - Size of the system disk, in GB. The valid values are 40~500. type: int auto_renew_period: choices: - 1 - 2 - 3 - 6 - 12 description: - The duration of the automatic renew the charge of the instance. Required when O(auto_renew=true). type: int availability_zone: aliases: - alicloud_zone - zone_id description: - Aliyun availability zone ID in which to launch the instance. If it is not specified, it will be allocated by system automatically. type: str max_bandwidth_out: default: 0 description: - Maximum outgoing bandwidth to the public network, measured in Mbps (Megabits per second). Required when O(allocate_public_ip=true). Ignored when O(allocate_public_ip=false). type: int allocate_public_ip: aliases: - assign_public_ip default: false description: - Whether allocate a public ip for the new instance. type: bool include_data_disks: default: true description: - Whether to change instance disks charge type when changing instance charge type. type: bool version_added: 0.2.0 version_added_collection: community.general alicloud_access_key: aliases: - access_key_id - access_key description: - Alibaba Cloud access key. If not set then the value of environment variable E(ALICLOUD_ACCESS_KEY), E(ALICLOUD_ACCESS_KEY_ID) will be used instead. type: str alicloud_secret_key: aliases: - secret_access_key - secret_key description: - Alibaba Cloud secret key. If not set then the value of environment variable E(ALICLOUD_SECRET_KEY), E(ALICLOUD_SECRET_ACCESS_KEY) will be used instead. type: str alicloud_assume_role: aliases: - assume_role description: - If provided with a role ARN, Ansible will attempt to assume this role using the supplied credentials. - The nested assume_role block supports C(alicloud_assume_role_arn), C(alicloud_assume_role_session_name), C(alicloud_assume_role_session_expiration) and C(alicloud_assume_role_policy). type: dict instance_charge_type: choices: - PrePaid - PostPaid default: PostPaid description: - The charge type of the instance. type: str internet_charge_type: choices: - PayByBandwidth - PayByTraffic default: PayByBandwidth description: - Internet charge type of ECS instance. type: str system_disk_category: choices: - cloud_efficiency - cloud_ssd default: cloud_efficiency description: - Category of the system disk. type: str alicloud_security_token: aliases: - security_token description: - The Alibaba Cloud security token. If not specified then the value of environment variable E(ALICLOUD_SECURITY_TOKEN) will be used instead. type: str shared_credentials_file: description: - This is the path to the shared credentials file. It can also be sourced from the E(ALICLOUD_SHARED_CREDENTIALS_FILE) environment variable. - If this is not set and a profile is specified, C(~/.aliyun/config.json) will be used. type: str system_disk_description: description: - Description of the system disk. type: str alicloud_assume_role_arn: aliases: - assume_role_arn description: - The Alibaba Cloud C(role_arn). The ARN of the role to assume. If ARN is set to an empty string, it does not perform role switching. It supports environment variable E(ALICLOUD_ASSUME_ROLE_ARN). ansible will execute with provided credentials. type: str alicloud_assume_role_session_name: aliases: - assume_role_session_name description: - The Alibaba Cloud session_name. The session name to use when assuming the role. If omitted, 'ansible' is passed to the AssumeRole call as session name. It supports environment variable E(ALICLOUD_ASSUME_ROLE_SESSION_NAME). type: str alicloud_assume_role_session_expiration: aliases: - assume_role_session_expiration description: - The Alibaba Cloud C(session_expiration). The time after which the established session for assuming role expires. Valid value range 900-3600 seconds. Default to 3600 (in this case Alicloud use own default value). It supports environment variable E(ALICLOUD_ASSUME_ROLE_SESSION_EXPIRATION). type: int
ids: description: List of ECS instance IDs returned: always sample: - i-12345er - i-3245fs type: list instances: contains: availability_zone: description: The availability zone of the instance is in. returned: always sample: cn-beijing-a type: str block_device_mappings: contains: attach_time: description: The time stamp when the attachment initiated. returned: always sample: '2018-06-25T04:08:26Z' type: str delete_on_termination: description: Indicates whether the volume is deleted on instance termination. returned: always sample: true type: bool device_name: description: The device name exposed to the instance (for example, /dev/xvda). returned: always sample: /dev/xvda type: str status: description: The attachment state. returned: always sample: in_use type: str volume_id: description: The ID of the cloud disk. returned: always sample: d-2zei53pjsi117y6gf9t6 type: str description: Any block device mapping entries for the instance. returned: always type: complex cpu: description: The CPU core count of the instance. returned: always sample: 4 type: int creation_time: description: The time the instance was created. returned: always sample: 2018-06-25T04:08Z type: str description: description: The instance description. returned: always sample: my ansible instance type: str eip: contains: allocation_id: description: The ID of the EIP. returned: always sample: eip-12345 type: str internet_charge_type: description: The internet charge type of the EIP. returned: always sample: paybybandwidth type: str ip_address: description: EIP address. returned: always sample: 42.10.2.2 type: str description: The attribution of EIP associated with the instance. returned: always type: complex expired_time: description: The time the instance will expire. returned: always sample: 2099-12-31T15:59Z type: str gpu: contains: amount: description: The count of the GPU. returned: always sample: 0 type: int spec: description: The specification of the GPU. returned: always sample: '' type: str description: The attribution of instance GPU. returned: always type: complex host_name: description: The host name of the instance. returned: always sample: iZ2zewaoZ type: str id: description: Alias of instance_id. returned: always sample: i-abc12345 type: str image_id: description: The ID of the image used to launch the instance. returned: always sample: m-0011223344 type: str inner_ip_address: description: The inner IPv4 address of the classic instance. returned: always sample: 10.0.0.2 type: str instance_charge_type: description: The instance charge type. returned: always sample: PostPaid type: str instance_id: description: ECS instance resource ID. returned: always sample: i-abc12345 type: str instance_name: description: The name of the instance. returned: always sample: my-ecs type: str instance_type: description: The instance type of the running instance. returned: always sample: ecs.sn1ne.xlarge type: str instance_type_family: description: The instance type family of the instance belongs. returned: always sample: ecs.sn1ne type: str internet_charge_type: description: The billing method of the network bandwidth. returned: always sample: PayByBandwidth type: str internet_max_bandwidth_in: description: Maximum incoming bandwidth from the internet network. returned: always sample: 200 type: int internet_max_bandwidth_out: description: Maximum incoming bandwidth from the internet network. returned: always sample: 20 type: int io_optimized: description: Indicates whether the instance is optimized for EBS I/O. returned: always sample: false type: bool memory: description: Memory size of the instance. returned: always sample: 8192 type: int network_interfaces: contains: mac_address: description: The MAC address. returned: always sample: 00:11:22:33:44:55 type: str network_interface_id: description: The ID of the network interface. returned: always sample: eni-01234567 type: str primary_ip_address: description: The primary IPv4 address of the network interface within the vswitch. returned: always sample: 10.0.0.1 type: str description: One or more network interfaces for the instance. returned: always type: complex osname: description: The operation system name of the instance owned. returned: always sample: CentOS type: str ostype: description: The operation system type of the instance owned. returned: always sample: linux type: str private_ip_address: description: The IPv4 address of the network interface within the subnet. returned: always sample: 10.0.0.1 type: str public_ip_address: description: The public IPv4 address assigned to the instance or eip address returned: always sample: 43.0.0.1 type: str resource_group_id: description: The id of the resource group to which the instance belongs. returned: always sample: my-ecs-group type: str security_groups: contains: group_id: description: The ID of the security group. returned: always sample: sg-0123456 type: str group_name: description: The name of the security group. returned: always sample: my-security-group type: str description: One or more security groups for the instance. elements: dict returned: always type: list spot_price_limit: description: - The maximum hourly price for the preemptible instance. returned: always sample: 0.97 type: float spot_strategy: description: - The bidding mode of the pay-as-you-go instance. returned: always sample: NoSpot type: str status: description: The current status of the instance. returned: always sample: running type: str tags: description: Any tags assigned to the instance. returned: always sample: null type: dict user_data: description: User-defined data. returned: always sample: null type: dict vpc_id: description: The ID of the VPC the instance is in. returned: always sample: vpc-0011223344 type: str vswitch_id: description: The ID of the vswitch in which the instance is running. returned: always sample: vsw-dew00abcdef type: str description: List of ECS instances returned: always type: complex