community.general.spotinst_aws_elastigroup (8.5.0) — module

Create, update or delete Spotinst AWS Elastigroups

Authors: Spotinst (@talzur)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Can create, update, or delete Spotinst AWS Elastigroups Launch configuration is part of the elastigroup configuration, so no additional modules are necessary for handling the launch configuration. You will have to have a credentials file in this location - <home>/.spotinst/credentials The credentials file must contain a row that looks like this token = <YOUR TOKEN> Full documentation available at https://help.spotinst.com/hc/en-us/articles/115003530285-Ansible-


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Basic configuration YAML example

- hosts: localhost
  tasks:
    - name: Create elastigroup
      community.general.spotinst_aws_elastigroup:
          state: present
          risk: 100
          availability_vs_cost: balanced
          availability_zones:
            - name: us-west-2a
              subnet_id: subnet-2b68a15c
          image_id: ami-f173cc91
          key_pair: spotinst-oregon
          max_size: 15
          min_size: 0
          target: 0
          unit: instance
          monitoring: true
          name: ansible-group
          on_demand_instance_type: c3.large
          product: Linux/UNIX
          load_balancers:
            - test-lb-1
          security_group_ids:
            - sg-8f4b8fe9
          spot_instance_types:
            - c3.large
          do_not_update:
            - image_id
            - target
      register: result
    - ansible.builtin.debug: var=result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# In this example, we create an elastigroup and wait 600 seconds to retrieve the instances, and use their private ips

- hosts: localhost
  tasks:
    - name: Create elastigroup
      community.general.spotinst_aws_elastigroup:
          state: present
          account_id: act-1a9dd2b
          risk: 100
          availability_vs_cost: balanced
          availability_zones:
            - name: us-west-2a
              subnet_id: subnet-2b68a15c
          tags:
            - Environment: someEnvValue
            - OtherTagKey: otherValue
          image_id: ami-f173cc91
          key_pair: spotinst-oregon
          max_size: 5
          min_size: 0
          target: 0
          unit: instance
          monitoring: true
          name: ansible-group-tal
          on_demand_instance_type: c3.large
          product: Linux/UNIX
          security_group_ids:
            - sg-8f4b8fe9
          block_device_mappings:
            - device_name: '/dev/sda1'
              ebs:
                volume_size: 100
                volume_type: gp2
          spot_instance_types:
            - c3.large
          do_not_update:
            - image_id
          wait_for_instances: true
          wait_timeout: 600
      register: result

    - name: Store private ips to file
      ansible.builtin.shell: echo {{ item.private_ip }}\n >> list-of-private-ips
      with_items: "{{ result.instances }}"
    - ansible.builtin.debug: var=result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# In this example, we create an elastigroup with multiple block device mappings, tags, and also an account id
# In organizations with more than one account, it is required to specify an account_id

- hosts: localhost
  tasks:
    - name: Create elastigroup
      community.general.spotinst_aws_elastigroup:
          state: present
          account_id: act-1a9dd2b
          risk: 100
          availability_vs_cost: balanced
          availability_zones:
            - name: us-west-2a
              subnet_id: subnet-2b68a15c
          tags:
            - Environment: someEnvValue
            - OtherTagKey: otherValue
          image_id: ami-f173cc91
          key_pair: spotinst-oregon
          max_size: 5
          min_size: 0
          target: 0
          unit: instance
          monitoring: true
          name: ansible-group-tal
          on_demand_instance_type: c3.large
          product: Linux/UNIX
          security_group_ids:
            - sg-8f4b8fe9
          block_device_mappings:
            - device_name: '/dev/xvda'
              ebs:
                volume_size: 60
                volume_type: gp2
            - device_name: '/dev/xvdb'
              ebs:
                volume_size: 120
                volume_type: gp2
          spot_instance_types:
            - c3.large
          do_not_update:
            - image_id
          wait_for_instances: true
          wait_timeout: 600
      register: result

    - name: Store private ips to file
      ansible.builtin.shell: echo {{ item.private_ip }}\n >> list-of-private-ips
      with_items: "{{ result.instances }}"
    - ansible.builtin.debug: var=result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# In this example we have set up block device mapping with ephemeral devices

- hosts: localhost
  tasks:
    - name: Create elastigroup
      community.general.spotinst_aws_elastigroup:
          state: present
          risk: 100
          availability_vs_cost: balanced
          availability_zones:
            - name: us-west-2a
              subnet_id: subnet-2b68a15c
          image_id: ami-f173cc91
          key_pair: spotinst-oregon
          max_size: 15
          min_size: 0
          target: 0
          unit: instance
          block_device_mappings:
            - device_name: '/dev/xvda'
              virtual_name: ephemeral0
            - device_name: '/dev/xvdb/'
              virtual_name: ephemeral1
          monitoring: true
          name: ansible-group
          on_demand_instance_type: c3.large
          product: Linux/UNIX
          load_balancers:
            - test-lb-1
          security_group_ids:
            - sg-8f4b8fe9
          spot_instance_types:
            - c3.large
          do_not_update:
            - image_id
            - target
      register: result
    - ansible.builtin.debug: var=result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# In this example we create a basic group configuration with a network interface defined.
# Each network interface must have a device index

- hosts: localhost
  tasks:
    - name: Create elastigroup
      community.general.spotinst_aws_elastigroup:
          state: present
          risk: 100
          availability_vs_cost: balanced
          network_interfaces:
            - associate_public_ip_address: true
              device_index: 0
          availability_zones:
            - name: us-west-2a
              subnet_id: subnet-2b68a15c
          image_id: ami-f173cc91
          key_pair: spotinst-oregon
          max_size: 15
          min_size: 0
          target: 0
          unit: instance
          monitoring: true
          name: ansible-group
          on_demand_instance_type: c3.large
          product: Linux/UNIX
          load_balancers:
            - test-lb-1
          security_group_ids:
            - sg-8f4b8fe9
          spot_instance_types:
            - c3.large
          do_not_update:
            - image_id
            - target
      register: result
    - ansible.builtin.debug: var=result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

# In this example we create a basic group configuration with a target tracking scaling policy defined

- hosts: localhost
  tasks:
    - name: Create elastigroup
      community.general.spotinst_aws_elastigroup:
          account_id: act-92d45673
          state: present
          risk: 100
          availability_vs_cost: balanced
          availability_zones:
            - name: us-west-2a
              subnet_id: subnet-79da021e
          image_id: ami-f173cc91
          fallback_to_od: true
          tags:
            - Creator: ValueOfCreatorTag
            - Environment: ValueOfEnvironmentTag
          key_pair: spotinst-labs-oregon
          max_size: 10
          min_size: 0
          target: 2
          unit: instance
          monitoring: true
          name: ansible-group-1
          on_demand_instance_type: c3.large
          product: Linux/UNIX
          security_group_ids:
            - sg-46cdc13d
          spot_instance_types:
            - c3.large
          target_tracking_policies:
            - policy_name: target-tracking-1
              namespace: AWS/EC2
              metric_name: CPUUtilization
              statistic: average
              unit: percent
              target: 50
              cooldown: 120
          do_not_update:
            - image_id
      register: result
    - ansible.builtin.debug: var=result

Inputs

    
id:
    description:
    - The group id if it already exists and you want to update, or delete it. This will
      not work unless the uniqueness_by field is set to id. When this is set, and the
      uniqueness_by field is set, the group will either be updated or deleted, but not
      created.
    type: str

ecs:
    description:
    - The ECS integration configuration.; Expects the following key - cluster_name (String)
    type: dict

chef:
    description:
    - The Chef integration configuration.; Expects the following keys - chef_server (String),
      organization (String), user (String), pem_key (String), chef_version (String)
    type: dict

name:
    description:
    - Unique name for elastigroup to be created, updated or deleted
    required: true
    type: str

risk:
    description:
    - Required if on demand is not set. The percentage of Spot instances to launch (0
      - 100).
    type: int

tags:
    description:
    - A list of tags to configure in the elastigroup. Please specify list of keys and
      values (key colon value);
    elements: dict
    type: list

unit:
    description:
    - The capacity unit to launch instances by.
    - 'The available choices are: V(instance), V(weight).'
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Create or delete the elastigroup
    type: str

token:
    description:
    - A Personal API Access Token issued by Spotinst.
    - 'When not specified, the module will try to obtain it, in that order, from: environment
      variable E(SPOTINST_TOKEN), or from the credentials path.'
    type: str

target:
    description:
    - The number of instances to launch
    required: true
    type: int

product:
    description:
    - Operation system type.
    - 'Available choices are: V(Linux/UNIX), V(SUSE Linux), V(Windows), V(Linux/UNIX (Amazon
      VPC)), V(SUSE Linux (Amazon VPC)).'
    required: true
    type: str

rancher:
    description:
    - The Rancher integration configuration.; Expects the following keys - version (String),
      access_key (String), secret_key (String), master_host (String)
    type: dict

signals:
    description:
    - A list of hash/dictionaries of signals to configure in the elastigroup; keys allowed
      are - name (String, required), timeout (Integer)
    elements: dict
    type: list

tenancy:
    description:
    - Dedicated vs shared tenancy.
    - 'The available choices are: V(default), V(dedicated).'
    type: str

image_id:
    description:
    - The image Id used to launch the instance.; In case of conflict between Instance
      type and image type, an error will be returned
    required: true
    type: str

key_pair:
    description:
    - Specify a Key Pair to attach to the instances
    type: str

max_size:
    description:
    - The upper limit number of instances that you can scale up to
    required: true
    type: int

min_size:
    description:
    - The lower limit number of instances that you can scale down to
    required: true
    type: int

opsworks:
    description:
    - The elastigroup OpsWorks integration configuration.; Expects the following key -
      layer_id (String)
    type: dict

user_data:
    description:
    - Base64-encoded MIME user data. Encode before setting the value.
    type: str

account_id:
    description:
    - Optional parameter that allows to set an account-id inside the module configuration.
      By default this is retrieved from the credentials path.
    type: str

kubernetes:
    description:
    - The Kubernetes integration configuration. Expects the following keys - api_server
      (String), token (String)
    type: dict

mesosphere:
    description:
    - The Mesosphere integration configuration. Expects the following key - api_server
      (String)
    type: dict

monitoring:
    description:
    - Describes whether instance Enhanced Monitoring is enabled
    type: str

elastic_ips:
    description:
    - List of ElasticIps Allocation Ids (example V(eipalloc-9d4e16f8)) to associate to
      the group instances
    elements: str
    type: list

persistence:
    description:
    - The Stateful elastigroup configuration.; Accepts the following keys - should_persist_root_device
      (Boolean), should_persist_block_devices (Boolean), should_persist_private_ip (Boolean)
    type: dict

right_scale:
    description:
    - The Rightscale integration configuration.; Expects the following keys - account_id
      (String), refresh_token (String)
    type: dict

roll_config:
    description:
    - Roll configuration.; If you would like the group to roll after updating, please
      use this feature. Accepts the following keys - batch_size_percentage(Integer, Required),
      grace_period - (Integer, Required), health_check_type(String, Optional)
    type: dict

iam_role_arn:
    description:
    - The instance profile iamRole arn
    - Only use iam_role_arn, or iam_role_name
    type: str

multai_token:
    description:
    - Token used for Multai configuration.
    type: str

spin_up_time:
    description:
    - Spin up time, in seconds, for the instance
    type: int

wait_timeout:
    description:
    - How long the module should wait for instances before failing the action.; Only works
      if wait_for_instances is True.
    type: int

do_not_update:
    default: []
    description:
    - TODO document.
    elements: str
    type: list

ebs_optimized:
    description:
    - Enable EBS optimization for supported instances which are not enabled by default.;
      Note - additional charges will be applied.
    type: bool

iam_role_name:
    description:
    - The instance profile iamRole name
    - Only use iam_role_arn, or iam_role_name
    type: str

uniqueness_by:
    choices:
    - id
    - name
    default: name
    description:
    - If your group names are not unique, you may use this feature to update or delete
      a specific group. Whenever this property is set, you must set a group_id in order
      to update or delete a group, otherwise a group will be created.
    type: str

fallback_to_od:
    description:
    - In case of no spots available, Elastigroup will launch an On-demand instance instead
    type: bool

load_balancers:
    description:
    - List of classic ELB names
    elements: str
    type: list

ebs_volume_pool:
    description:
    - A list of hash/dictionaries of EBS devices to reattach to the elastigroup when available;
      '[{"key":"value", "key":"value"}]'; keys allowed are - volume_ids (List of Strings),
      device_name (String)
    elements: dict
    type: list

lifetime_period:
    description:
    - Lifetime period
    type: int

on_demand_count:
    description:
    - Required if risk is not set
    - Number of on demand instances to launch. All other instances will be spot instances.;
      Either set this parameter or the risk parameter
    type: int

scheduled_tasks:
    description:
    - A list of hash/dictionaries of scheduled tasks to configure in the elastigroup;
      '[{"key":"value", "key":"value"}]'; keys allowed are - adjustment (Integer), scale_target_capacity
      (Integer), scale_min_capacity (Integer), scale_max_capacity (Integer), adjustment_percentage
      (Integer), batch_size_percentage (Integer), cron_expression (String), frequency
      (String), grace_period (Integer), task_type (String, required), is_enabled (Boolean)
    elements: dict
    type: list

shutdown_script:
    description:
    - The Base64-encoded shutdown script that executes prior to instance termination.
      Encode before setting.
    type: str

credentials_path:
    default: ~/.spotinst/credentials
    description:
    - Optional parameter that allows to set a non-default credentials path.
    type: path

draining_timeout:
    description:
    - Time for instance to be drained from incoming requests and deregistered from ELB
      before termination.
    type: int

elastic_beanstalk:
    description:
    - Placeholder parameter for future implementation of Elastic Beanstalk configurations.
    type: dict

health_check_type:
    description:
    - The service to use for the health check.
    - 'The choices available are: V(ELB), V(HCS), V(TARGET_GROUP), V(MLB), V(EC2).'
    type: str

target_group_arns:
    description:
    - List of target group arns instances should be registered to
    elements: str
    type: list

availability_zones:
    description:
    - A list of hash/dictionaries of Availability Zones that are configured in the elastigroup;
      '[{"key":"value", "key":"value"}]'; keys allowed are name (String), subnet_id (String),
      placement_group_name (String),
    elements: dict
    required: true
    type: list

network_interfaces:
    description:
    - A list of hash/dictionaries of network interfaces to add to the elastigroup; '[{"key":"value",
      "key":"value"}]'; keys allowed are - description (String), device_index (Integer),
      secondary_private_ip_address_count (Integer), associate_public_ip_address (Boolean),
      delete_on_termination (Boolean), groups (List of Strings), network_interface_id
      (String), private_ip_address (String), subnet_id (String), associate_ipv6_address
      (Boolean), private_ip_addresses (List of Objects, Keys are privateIpAddress (String,
      required) and primary (Boolean))
    elements: dict
    type: list

security_group_ids:
    description:
    - One or more security group IDs. ; In case of update it will override the existing
      Security Group with the new given array
    elements: str
    required: true
    type: list

wait_for_instances:
    default: false
    description:
    - Whether or not the elastigroup creation / update actions should wait for the instances
      to spin
    type: bool

spot_instance_types:
    description:
    - Spot instance type that will be provisioned.
    elements: str
    required: true
    type: list

up_scaling_policies:
    description:
    - A list of hash/dictionaries of scaling policies to configure in the elastigroup;
      '[{"key":"value", "key":"value"}]'; keys allowed are - policy_name (String, required),
      namespace (String, required), metric_name (String, required), dimensions (List of
      Objects, Keys allowed are name (String, required) and value (String)), statistic
      (String, required) evaluation_periods (String, required), period (String, required),
      threshold (String, required), cooldown (String, required), unit (String, required),
      operator (String, required), action_type (String, required), adjustment (String),
      min_target_capacity (String), target (String), maximum (String), minimum (String)
    elements: dict
    type: list

availability_vs_cost:
    description:
    - The strategy orientation.
    - 'The choices available are: V(availabilityOriented), V(costOriented), V(balanced).'
    required: true
    type: str

block_device_mappings:
    description:
    - A list of hash/dictionaries of Block Device Mappings for elastigroup instances;
      You can specify virtual devices and EBS volumes.; '[{"key":"value", "key":"value"}]';
      keys allowed are device_name (List of Strings), virtual_name (String), no_device
      (String), ebs (Object, expects the following keys- delete_on_termination(Boolean),
      encrypted(Boolean), iops (Integer), snapshot_id(Integer), volume_type(String), volume_size(Integer))
    elements: dict
    type: list

down_scaling_policies:
    description:
    - A list of hash/dictionaries of scaling policies to configure in the elastigroup;
      '[{"key":"value", "key":"value"}]'; keys allowed are - policy_name (String, required),
      namespace (String, required), metric_name (String, required), dimensions ((List
      of Objects), Keys allowed are name (String, required) and value (String)), statistic
      (String, required), evaluation_periods (String, required), period (String, required),
      threshold (String, required), cooldown (String, required), unit (String, required),
      operator (String, required), action_type (String, required), adjustment (String),
      max_target_capacity (String), target (String), maximum (String), minimum (String)
    elements: dict
    type: list

multai_load_balancers:
    description:
    - Configuration parameters for Multai load balancers.
    elements: dict
    type: list

on_demand_instance_type:
    description:
    - On-demand instance type that will be provisioned
    type: str

target_tracking_policies:
    description:
    - A list of hash/dictionaries of target tracking policies to configure in the elastigroup;
      '[{"key":"value", "key":"value"}]'; keys allowed are - policy_name (String, required),
      namespace (String, required), source (String, required), metric_name (String, required),
      statistic (String, required), unit (String, required), cooldown (String, required),
      target (String, required)
    elements: dict
    type: list

health_check_grace_period:
    description:
    - The amount of time, in seconds, after the instance has launched to start and check
      its health.
    - If not specified, it defaults to V(300).
    type: int

utilize_reserved_instances:
    description:
    - In case of any available Reserved Instances, Elastigroup will utilize your reservations
      before purchasing Spot instances.
    type: bool

terminate_at_end_of_billing_hour:
    description:
    - Terminate at the end of billing hour
    type: bool

health_check_unhealthy_duration_before_replacement:
    description:
    - Minimal mount of time instance should be unhealthy for us to consider it unhealthy.
    type: int

Outputs

group_id:
  description: Created / Updated group's ID.
  returned: success
  sample: sig-12345
  type: str
instances:
  description: List of active elastigroup instances and their details.
  returned: success
  sample:
  - availabilityZone: us-west-2b
    createdAt: '2017-07-17T12:46:18.000Z'
    instanceId: i-09640ad8678234c
    instanceType: m4.large
    privateIp: 180.0.2.244
    product: Linux/UNIX
    spotInstanceRequestId: sir-regs25zp
    status: fulfilled
  type: dict