Amazon ec2 使用Ansible设置具有实例中断行为的多个spot实例
我知道这似乎与过去提出的其他问题有关,但我觉得并非如此。 你将对此作出判断 我已经使用Ansible 1.5年了,我知道它不是提供基础设施的最佳工具,但它满足了我的需要 我正在使用AWS作为我的云提供商 是否有任何方法可以使Ansible提供相同类型的多个spot实例(类似于ec2Ansible模块中的count属性),并将实例中断行为设置为停止(行为),而不是默认的终止 我的目标: 使用对Amazon的不同EC2_spot_请求设置多个EC2实例。(每个实例的现场请求) 但是,我不想使用默认的instance\u interruption\u行为,即terminate,而是希望将其设置为stop(行为) 到目前为止我所做的: 我知道Ansible有以下模块来处理ec2基础设施。 主要是 ec2. 不要与 ec2_实例模块 我可以使用ec2模块设置spot实例,正如我到目前为止所做的那样,如下所示:Amazon ec2 使用Ansible设置具有实例中断行为的多个spot实例,amazon-ec2,ansible,ansible-2.x,amazon-ec2-spot-market,Amazon Ec2,Ansible,Ansible 2.x,Amazon Ec2 Spot Market,我知道这似乎与过去提出的其他问题有关,但我觉得并非如此。 你将对此作出判断 我已经使用Ansible 1.5年了,我知道它不是提供基础设施的最佳工具,但它满足了我的需要 我正在使用AWS作为我的云提供商 是否有任何方法可以使Ansible提供相同类型的多个spot实例(类似于ec2Ansible模块中的count属性),并将实例中断行为设置为停止(行为),而不是默认的终止 我的目标: 使用对Amazon的不同EC2_spot_请求设置多个EC2实例。(每个实例的现场请求) 但是,我不想使用默认的
ec2:
key_name: mykey
region: us-west-1
instance_type: "{{ instance_type }}"
image: "{{ instance_ami }}"
wait: yes
wait_timeout: 100
spot_price: "{{ spot_bid }}"
spot_wait_timeout: 600
spot_type: persistent
group_id: "{{ created_sg.group_id }}"
instance_tags:
Name: "Name"
count: "{{ my_count }}"
vpc_subnet_id: " {{ subnet }}"
assign_public_ip: yes
monitoring: no
volumes:
- device_name: /dev/sda1
volume_type: gp2
volume_size: "{{ volume_size }}"
预问题:
上面的示例模块很好,很干净,允许我使用ec2模块和count属性根据自己的需求设置spot实例
但是,它不允许我将实例中断行为设置为停止(除非我正在工作),它只是默认终止
其他模块:
将在Ansible 2.8.0版(目前仅在开发中提供)上发布的新模块名为:ec2_启动_模板
此模块为您提供了更多属性,允许您结合ec2_实例模块将所需的实例_中断_行为设置为停止(行为)。
这就是我所做的:
- hosts: 127.0.0.1
connection: local
gather_facts: True
vars_files:
- vars/main.yml
tasks:
- name: "create security group"
include_tasks: tasks/create_sg.yml
- name: "Create launch template to support interruption behavior 'STOP' for spot instances"
ec2_launch_template:
name: spot_launch_template
region: us-west-1
key_name: mykey
instance_type: "{{ instance_type }}"
image_id: "{{ instance_ami }}"
instance_market_options:
market_type: spot
spot_options:
instance_interruption_behavior: stop
max_price: "{{ spot_bid }}"
spot_instance_type: persistent
monitoring:
enabled: no
block_device_mappings:
- device_name: /dev/sda1
ebs:
volume_type: gp2
volume_size: "{{ manager_instance_volume_size }}"
register: my_template
- name: "setup up a single spot instance"
ec2_instance:
instance_type: "{{ instance_type }}"
tags:
Name: "My_Spot"
launch_template:
id: "{{ my_template.latest_template.launch_template_id }}"
security_groups:
- "{{ created_sg.group_id }}"
主要问题:
从上面的代码片段可以看出,ec2_启动_模板Ansible模块不支持count属性,ec2_实例模块也不支持该属性
是否有任何方法可以使ansible提供相同类型的多个实例(类似于ec2 ansible模块中的count属性)?通常,如果您同时管理大量ec2实例的副本,您可能希望使用或 有一个模块允许您通过ansible管理自动缩放组。这将允许您基于该启动模板部署多个EC2实例 解决此问题的另一种技术是,如果AWS云信息模板或地形平面图支持您想要做的事情,则使用or模块。这还允许您在必要时提供基础架构模板之前,使用Jinja2模板语法进行一些巧妙的模板生成