Kohei Nozaki
Kohei Nozaki

Reputation: 1152

Ansible - How to launch(purchase) a reserved EC2 instance

How can I launch(purchase) a reserved EC2 instance using Ansible with EC2 module? I've googled using words something like 'ec2 reserved instance ansible' but no joy.

Or should I use AWS CLI instead?

Upvotes: 2

Views: 820

Answers (3)

Eric Citaire
Eric Citaire

Reputation: 4513

I just made a PR which might help you.

You could use it as follows:

- name: Purchase reserved instances
  boto3:
    name: ec2
    region: us-east-1
    operation: purchase_reserved_instances_offering
    parameters:
      ReservedInstancesOfferingId: 9a06095a-bdc6-47fe-a94a-2a382f016040
      InstanceCount: 3
      LimitPrice:
        Amount: 123.0
        CurrencyCode: USD
  register: result

- debug: var=result

If you're interrested by this feature, feel free to vote up on the PR. :)

Upvotes: 2

Valeriy Solovyov
Valeriy Solovyov

Reputation: 5648

Or you can create Ansible module. Also there are already created modules that you can use as examples ansible-modules-extras/cloud/amazon.

PS:

Modules can be written in any language and are found in the path specified by ANSIBLE_LIBRARY or the --module-path command line option.

By default, everything that ships with ansible is pulled from its source tree, but additional paths can be added.

The directory ”./library”, alongside your top level playbooks, is also automatically added as a search directory.

Upvotes: 2

Naveen Vijay
Naveen Vijay

Reputation: 16522

I looked into the Cloud module list and found there isn't any modules out of the box that supports reserved instance - I think you try building a wrapper over the AWS CLI or Python Boto SDK [ or any SDK ].

This is the pseudo code for the playbook :

---
- hosts: localhost
  connection: local
  gather_facts: false

  tasks:

    - name: 'Calling Python Code to reserve instance' 
      raw: python reserve-ec2-instance.py args

Upvotes: 1

Related Questions