amazon.aws.ec2_spot_instance module – Request, stop, reboot or cancel spot instance
Note
This module is part of the amazon.aws collection (version 8.2.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
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: amazon.aws.ec2_spot_instance
.
New in amazon.aws 2.0.0
Synopsis
Creates or cancels spot instance requests.
Requirements
The below requirements are needed on the host that executes this module.
python >= 3.6
boto3 >= 1.26.0
botocore >= 1.29.0
Parameters
Parameter |
Comments |
---|---|
AWS access key ID. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The aws_access_key and profile options are mutually exclusive. The aws_access_key_id alias was added in release 5.1.0 for consistency with the AWS botocore SDK. The ec2_access_key alias has been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
The location of a CA Bundle to use when validating SSL certificates. The |
|
A dictionary to modify the botocore configuration. Parameters can be found in the AWS documentation https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config. |
|
The idempotency token you provided when you launched the instance, if applicable. |
|
Number of instances to launch. Default: |
|
Use a The Choices:
|
|
URL to connect to instead of the default AWS endpoints. While this can be used to connection to other AWS-compatible services the amazon.aws and community.aws collections are only tested against AWS. The The ec2_url and s3_url aliases have been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
The behavior when a Spot Instance is interrupted. Choices:
|
|
Launch group for spot requests, see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/how-spot-instances-work.html#spot-launch-group. |
|
The launch specification. |
|
A list of hash/dictionaries of volumes to add to the new instance. |
|
The device name (for example, /dev/sdh or xvdh). |
|
Parameters used to automatically set up EBS volumes when the instance is launched, see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.request_spot_instances. |
|
To omit the device from the block device mapping, specify an empty string. |
|
The virtual device name |
|
Whether instance is using optimized EBS volumes, see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html. Choices:
|
|
The IAM instance profile. |
|
The Amazon Resource Name (ARN) of the instance profile. Only one of |
|
The name of the instance profile. Only one of |
|
The ID of the AMI. |
|
Instance type to use for the instance, see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html. Required when creating a new instance. |
|
The ID of the kernel. |
|
Key to use on the instance. The SSH key must already exist in AWS in order to use this argument. Keys can be created / deleted using the amazon.aws.ec2_key module. |
|
Indicates whether basic or detailed monitoring is enabled for the instance. |
|
Indicates whether detailed monitoring is enabled. Otherwise, basic monitoring is enabled. Choices:
|
|
One or more network interfaces. If you specify a network interface, you must specify subnet IDs and security group IDs using the network interface. Default: |
|
Indicates whether to assign a carrier IP address to the network interface. Choices:
|
|
Indicates whether to assign a public IPv4 address to an instance you launch in a VPC. Choices:
|
|
If set to true , the interface is deleted when the instance is terminated. You can specify true only if creating a new network interface when launching an instance. Choices:
|
|
The description of the network interface. Applies only if creating a network interface when launching an instance. |
|
The position of the network interface in the attachment order. A primary network interface has a device index of 0. If you specify a network interface when launching an instance, you must specify the device index. |
|
The IDs of the security groups for the network interface. Applies only if creating a network interface when launching an instance. |
|
The type of network interface. Choices:
|
|
The number of IPv4 delegated prefixes to be automatically assigned to the network interface |
|
One or more IPv4 delegated prefixes to be assigned to the network interface. |
|
A number of IPv6 addresses to assign to the network interface |
|
One or more IPv6 addresses to assign to the network interface. |
|
The IPv6 address. |
|
The number of IPv6 delegated prefixes to be automatically assigned to the network interface |
|
One or more IPv6 delegated prefixes to be assigned to the network interface |
|
The index of the network card. |
|
The ID of the network interface. |
|
The private IPv4 address of the network interface |
|
One or more private IPv4 addresses to assign to the network interface |
|
The number of secondary private IPv4 addresses. |
|
The ID of the subnet associated with the network interface |
|
The placement information for the instance. |
|
The Availability Zone. |
|
The name of the placement group. |
|
the tenancy of the host Choices:
|
|
The ID of the RAM disk. |
|
Security group id (or list of ids) to use with the instance. |
|
Security group name (or list of group names) to use with the instance. Only supported with EC2 Classic. To launch in a VPC, use |
|
The ID of the subnet in which to launch the instance. |
|
The base64-encoded user data for the instance. User data is limited to 16 KB. |
|
A named AWS profile to use for authentication. See the AWS documentation for more information about named profiles https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html. The The profile option is mutually exclusive with the aws_access_key, aws_secret_key and security_token options. |
|
The AWS region to use. For global services such as IAM, Route53 and CloudFront, region is ignored. The See the Amazon AWS documentation for more information http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region. The Support for the |
|
AWS secret access key. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The secret_key and profile options are mutually exclusive. The aws_secret_access_key alias was added in release 5.1.0 for consistency with the AWS botocore SDK. The ec2_secret_key alias has been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
AWS STS session token for use with temporary credentials. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The security_token and profile options are mutually exclusive. Aliases aws_session_token and session_token were added in release 3.2.0, with the parameter being renamed from security_token to session_token in release 6.0.0. The security_token, aws_security_token, and access_token aliases have been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
List of strings with IDs of spot requests to be cancelled |
|
Maximum spot price to bid. If not set, a regular on-demand instance is requested. A spot request is made with this maximum bid. When it is filled, the instance is started. |
|
The type of spot request. After being interrupted a Choices:
|
|
Whether the spot request should be created or removed. When When Choices:
|
|
A dictionary of key-value pairs for tagging the Spot Instance request on creation. |
|
Boolean value to set whether or not to terminate instances associated to spot request. Can be used only when Choices:
|
|
When set to Setting validate_certs=false is strongly discouraged, as an alternative, consider setting aws_ca_bundle instead. Choices:
|
|
Name for logical grouping of spot requests. All spot instances in the request are launched in the same availability zone. |
Notes
Note
Caution: For modules, environment variables and configuration files are read from the Ansible ‘host’ context and not the ‘controller’ context. As such, files may need to be explicitly copied to the ‘host’. For lookup and connection plugins, environment variables and configuration files are read from the Ansible ‘controller’ context and not the ‘host’ context.
The AWS SDK (boto3) that Ansible uses may also read defaults for credentials and other settings, such as the region, from its configuration files in the Ansible ‘host’ context (typically
~/.aws/credentials
). See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html for more information.
Examples
# Note: These examples do not set authentication details, see the AWS Guide for details.
- name: Simple Spot Request Creation
amazon.aws.ec2_spot_instance:
launch_specification:
image_id: ami-123456789
key_name: my-keypair
instance_type: t2.medium
- name: Spot Request Creation with more options
amazon.aws.ec2_spot_instance:
launch_specification:
image_id: ami-123456789
key_name: my-keypair
instance_type: t2.medium
subnet_id: subnet-12345678
block_device_mappings:
- device_name: /dev/sdb
ebs:
delete_on_termination: true
volume_type: gp3
volume_size: 5
- device_name: /dev/sdc
ebs:
delete_on_termination: true
volume_type: io2
volume_size: 30
network_interfaces:
- associate_public_ip_address: false
delete_on_termination: true
device_index: 0
placement:
availability_zone: us-west-2a
monitoring:
enabled: false
spot_price: 0.002
tags:
Environment: Testing
- name: Spot Request Termination
amazon.aws.ec2_spot_instance:
spot_instance_request_ids: ['sir-12345678', 'sir-abcdefgh']
state: absent
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Details of the cancelled spot instance request. Returned: when cancellation is successful Sample: |
|
The spot instance request details after creation. Returned: when success Sample: |