我知道这似乎与过去提出的其他问题有关,但我觉得并非如此。你将对此作出判断。
我已经使用Ansible 1.5年了,我知道它不是提供基础设施的最佳工具,但是满足我的需求就足够了。
我正在使用AWS作为我的云提供商
是否有任何方法可以使Ansible提供相同类型的多个spot实例(类似于ec2 ansible模块中的count属性),将其设置为stop(behavior)而不是默认的终止?
我的目标:
使用不同的EC2设置多个ec2_spot_requests实例。(每个实例都有请求),但我希望将其设置为stop(行为),而不是使用默认的终止instance_interruption_behavior。
到目前为止我所做的:
我知道Ansible有下面的模块来处理ec2基础结构。主要是
ec2. module.html
不要与ec2_instance模块混淆。
我可以像到目前为止所做的那样,使用ec2模块来设置spot实例,如下所示:
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实例。
但是,它不允许我将instance_interruption_behavior设置为stop(除非我担心),它只是默认终止。
其他模块:
要在ec2_launch_template AnbleVersion2.8.0上发布(目前只在开发中可用),有一个名为:的新模块
这个模块为您提供更多的属性,这允许您使用ec2_instance模块的组合来设置所需的instance_interruption_behavior以停止(行为)。我就是这样做的:
- 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_launch_template Ansible模块不支持count属性,ec2_instance模块也不允许它。
是否有任何方法使ansible提供相同类型的多个实例(类似于ec2 ansible模块中的count属性)?
https://stackoverflow.com/questions/55440089
复制相似问题