community.general.spotinst_aws_elastigroup 模块 – 创建、更新或删除 Spotinst AWS Elastigroups
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible
包,则可能已安装此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.general
。您需要其他要求才能使用此模块,请参阅 要求 以了解详情。
要在 playbook 中使用它,请指定:community.general.spotinst_aws_elastigroup
。
概要
可以创建、更新或删除 Spotinst AWS Elastigroups。启动配置是弹性组配置的一部分,因此无需其他模块来处理启动配置。您必须在此位置拥有一个凭据文件 - <home>/.spotinst/credentials。凭据文件必须包含如下所示的行:token = <YOUR TOKEN> 完整文档可在 https://help.spotinst.com/hc/en-us/articles/115003530285-Ansible 查看。
要求
执行此模块的主机需要以下要求。
spotinst_sdk >= 1.0.38
参数
参数 |
注释 |
---|---|
允许在模块配置中设置 account-id 的可选参数。默认情况下,这是从凭据路径检索的。 |
|
策略方向。 可用的选项为: |
|
在弹性组中配置的可用区哈希/字典列表;‘[{“key”:”value”, “key”:”value”}]’;允许的键为 name(字符串)、subnet_id(字符串)、placement_group_name(字符串)。 |
|
弹性组实例的块设备映射哈希/字典列表;您可以指定虚拟设备和 EBS 卷;‘[{“key”:”value”, “key”:”value”}]’;允许的键为 device_name(字符串列表)、virtual_name(字符串)、no_device(字符串)、ebs(对象,期望以下键 - delete_on_termination(布尔值)、encrypted(布尔值)、iops(整数)、snapshot_id(整数)、volume_type(字符串)、volume_size(整数)) |
|
Chef 集成配置;期望以下键 - chef_server(字符串)、organization(字符串)、user(字符串)、pem_key(字符串)、chef_version(字符串) |
|
允许设置非默认凭据路径的可选参数。 默认值: |
|
待补充文档。 默认值: |
|
要在弹性组中配置的缩放策略的哈希/字典列表;‘[{“key”:”value”, “key”:”value”}]’;允许的键为 - policy_name(字符串,必需)、namespace(字符串,必需)、metric_name(字符串,必需)、dimensions(对象列表),允许的键为 name(字符串,必需)和 value(字符串)、statistic(字符串,必需)、evaluation_periods(字符串,必需)、period(字符串,必需)、threshold(字符串,必需)、cooldown(字符串,必需)、unit(字符串,必需)、operator(字符串,必需)、action_type(字符串,必需)、adjustment(字符串)、max_target_capacity(字符串)、target(字符串)、maximum(字符串)、minimum(字符串) |
|
实例在终止之前从传入请求中移除并在 ELB 中注销的时间。 |
|
为默认情况下未启用的受支持实例启用 EBS 优化;注意 - 将收取额外费用。 选项
|
|
可在时重新附加到弹性组的 EBS 设备的哈希/字典列表;‘[{“key”:”value”, “key”:”value”}]’;允许的键为 - volume_ids(字符串列表)、device_name(字符串) |
|
ECS 集成配置;期望以下键 - cluster_name(字符串) |
|
将来实现 Elastic Beanstalk 配置的占位符参数。 |
|
要与组实例关联的 ElasticIps 分配 ID 列表(例如 |
|
如果无可用 Spot 实例,弹性组将启动一个按需实例。 选项
|
|
实例启动后开始检查其运行状况的时间量(以秒为单位)。 如果未指定,则默认为 |
|
用于运行状况检查的服务。 可用的选项为: |
|
实例应处于不健康状态的最小时间量,以便我们将其视为不健康。 |
|
实例配置文件 iamRole arn 仅使用 iam_role_arn 或 iam_role_name |
|
实例配置文件 iamRole 名称 仅使用 iam_role_arn 或 iam_role_name |
|
如果组已存在并且您想更新或删除它,则为组 ID。除非 uniqueness_by 字段设置为 id,否则此操作无效。当此字段设置且 uniqueness_by 字段设置时,组将被更新或删除,但不会被创建。 |
|
用于启动实例的镜像 ID;如果实例类型和镜像类型冲突,则会返回错误。 |
|
指定要附加到实例的密钥对。 |
|
Kubernetes 集成配置。需要以下键 - api_server(字符串)、token(字符串)。 |
|
生命周期。 |
|
经典 ELB 名称列表。 |
|
您可以扩展到的实例数量上限。 |
|
Mesosphere 集成配置。需要以下键 - api_server(字符串)。 |
|
您可以缩减到的实例数量下限。 |
|
描述是否启用了实例增强型监控。 |
|
Multai 负载均衡器的配置参数。 |
|
用于 Multai 配置的令牌。 |
|
要创建、更新或删除的弹性组的唯一名称。 |
|
要添加到弹性组的网络接口的哈希/字典列表;‘[{“key”:”value”, “key”:”value”}]’;允许的键为 - description(字符串)、device_index(整数)、secondary_private_ip_address_count(整数)、associate_public_ip_address(布尔值)、delete_on_termination(布尔值)、groups(字符串列表)、network_interface_id(字符串)、private_ip_address(字符串)、subnet_id(字符串)、associate_ipv6_address(布尔值)、private_ip_addresses(对象列表,键为 privateIpAddress(字符串,必填)和 primary(布尔值)) |
|
如果未设置风险,则为必填项。 要启动的按需实例数量。所有其他实例都将是抢占实例;设置此参数或风险参数。 |
|
将配置的按需实例类型。 |
|
弹性组 OpsWorks 集成配置;需要以下键 - layer_id(字符串)。 |
|
有状态弹性组配置;接受以下键 - should_persist_root_device(布尔值)、should_persist_block_devices(布尔值)、should_persist_private_ip(布尔值)。 |
|
操作系统类型。 可用选项为: |
|
Rancher 集成配置;需要以下键 - version(字符串)、access_key(字符串)、secret_key(字符串)、master_host(字符串)。 |
|
Rightscale 集成配置;需要以下键 - account_id(字符串)、refresh_token(字符串)。 |
|
如果未设置按需实例,则为必填项。要启动的抢占实例的百分比 (0 - 100)。 |
|
滚动配置;如果您希望在更新后组进行滚动,请使用此功能。接受以下键 - batch_size_percentage(整数,必填)、grace_period(整数,必填)、health_check_type(字符串,可选)。 |
|
要配置在弹性组中的计划任务的哈希/字典列表;‘[{“key”:”value”, “key”:”value”}]’;允许的键为 - adjustment(整数)、scale_target_capacity(整数)、scale_min_capacity(整数)、scale_max_capacity(整数)、adjustment_percentage(整数)、batch_size_percentage(整数)、cron_expression(字符串)、frequency(字符串)、grace_period(整数)、task_type(字符串,必填)、is_enabled(布尔值)。 |
|
一个或多个安全组 ID;如果进行更新,它将使用新的给定数组覆盖现有的安全组。 |
|
在实例终止之前执行的 Base64 编码关机脚本。设置前进行编码。 |
|
要配置在弹性组中的信号的哈希/字典列表;允许的键为 - name(字符串,必填)、timeout(整数)。 |
|
实例的启动时间(秒)。 |
|
将配置的抢占实例类型。 |
|
创建或删除弹性组。 选项
|
|
要在弹性组中配置的标签列表。请指定键和值列表(键冒号值); |
|
要启动的实例数量。 |
|
实例应注册到的目标组 ARN 列表。 |
|
要配置在弹性组中的目标跟踪策略的哈希/字典列表;‘[{“key”:”value”, “key”:”value”}]’;允许的键为 - policy_name(字符串,必填)、namespace(字符串,必填)、source(字符串,必填)、metric_name(字符串,必填)、statistic(字符串,必填)、unit(字符串,必填)、cooldown(字符串,必填)、target(字符串,必填)。 |
|
专用与共享租户。 可用选项为: |
|
在账单小时结束时终止。 选项
|
|
Spotinst 颁发的个人 API 访问令牌。 如果未指定,模块将尝试按以下顺序获取它:环境变量 |
|
如果您的组名称不唯一,您可以使用此功能来更新或删除特定组。每当设置此属性时,都必须设置 group_id 以更新或删除组,否则将创建一个组。 选项
|
|
按其启动实例的容量单位。 可用选项为: |
|
要配置在弹性组中的扩展策略的哈希/字典列表;‘[{“key”:”value”, “key”:”value”}]’;允许的键为 - policy_name(字符串,必填)、namespace(字符串,必填)、metric_name(字符串,必填)、dimensions(对象列表,允许的键为 name(字符串,必填)和 value(字符串))、statistic(字符串,必填)evaluation_periods(字符串,必填)、period(字符串,必填)、threshold(字符串,必填)、cooldown(字符串,必填)、unit(字符串,必填)、operator(字符串,必填)、action_type(字符串,必填)、adjustment(字符串)、min_target_capacity(字符串)、target(字符串)、maximum(字符串)、minimum(字符串)。 |
|
Base64 编码的 MIME 用户数据。设置值前进行编码。 |
|
如果有任何可用的预留实例,弹性组将在购买抢占实例之前利用您的预留。 选项
|
|
弹性组创建/更新操作是否应等待实例启动。 选项
|
|
模块在操作失败前应等待实例的时间长度;仅当 wait_for_instances 为 True 时有效。 |
属性
属性 |
支持 |
描述 |
---|---|---|
支持:不支持 |
可以在 |
|
支持:不支持 |
在差异模式下,将返回有关已更改内容(或可能需要在 |
示例
# 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
# 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
# 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
# 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
# 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
# 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
返回值
公共返回值已在此处记录,以下是此模块独有的字段。
键 |
描述 |
---|---|
已创建/更新的组的 ID。 已返回:成功 示例: |
|
活动弹性组实例及其详细信息列表。 已返回:成功 示例: |