Skip to content

ec2_instance: Add support to run spot instances #1338

Open

Description

@tgadiev

Summary

It appears that this module lacks a useful ability, as mentioned in the documentation. The recommendation is to use the ec2_spot_instance module. However, the ec2_spot_instance module does not support setting the instance metadata option, which is highly needed in some cases. As a result, there is a significant gap in functionality. The options available are to run spot instances using the ec2_spot_instance module without an adjusted metadata option, or to run instances using the ec2_instance module that has this feature, but this way, you cannot start spot instances. According to [boto documentation], adding spot support is relatively simple; it just requires adding the InstanceMarketOptions properties to the build_top_level_options function.

Issue Type

Feature Idea

Component Name

ec2_instance

Additional Information

I would like to have it like this:

- name: start spot instance with metadata options
  amazon.aws.ec2_instance:
    name: "spot-metadataoptions-instance"
    vpc_subnet_id: subnet-5calable
    instance_type: t3.small
    image_id: ami-123456
    tags:
      Environment: Testing
    metadata_options:
      http_endpoint: enabled
      http_tokens: optional
    spot_options:
      spot_instance_type: 'one-time'
      max_price: '0.055' 

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Activity

  1. ansibullbot commented on Jan 13, 2023

    @ansibullbot

    Files identified in the description:

    If these files are inaccurate, please update the component name section of the description or use the !component bot command.

    click here for bot help

  2. ansibullbot commented on Jan 13, 2023

    @ansibullbot
  3. added
    feature
    module
    plugins
    on Jan 13, 2023
  4. alinabuzachis commented on Jan 13, 2023

    @alinabuzachis
    Collaborator

    @tgadiev Thank for for reporting this. instance_market_options can be set by creating an EC2 launch template ( https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/ec2_launch_template.py#L184).
    You can then feed the launch template to the EC2 instance by specifying the launch_template option https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/ec2_instance.py#L223

    Let me know please if this helps.

  5. tgadiev commented on Jan 15, 2023

    @tgadiev
    Author

    @alinabuzachis Yes, that works in my case. With some drawbacks, but in general it's applicable. Thanks for highlighting this option! But I still think that adding this ability to ec2_instance module makes sense.

  6. vitabaks commented on Sep 17, 2026

    @vitabaks

    Are there any updates planned on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuremoduleplugins

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions