Amazon ec2 如果其他人签入Ansible,可以这样做吗?
目前,我的spot EC2配置重头戏如下所示:Amazon ec2 如果其他人签入Ansible,可以这样做吗?,amazon-ec2,ansible,Amazon Ec2,Ansible,目前,我的spot EC2配置重头戏如下所示: - name: Provisioning Spot instaces ec2: spot_price: 0.50 spot_wait_timeout: 300 assign_public_ip: no aws_access_key: "{{ aws_id }}" aws_secret_key: "{{ aws_key }}" region: "{{ aws_region }}" image
- name: Provisioning Spot instaces
ec2:
spot_price: 0.50
spot_wait_timeout: 300
assign_public_ip: no
aws_access_key: "{{ aws_id }}"
aws_secret_key: "{{ aws_key }}"
region: "{{ aws_region }}"
image: "{{ image_instance }}"
instance_type: "{{ large_instance }}"
key_name: "{{ ssh_keyname }}"
count: 3
state: present
group_id: "{{ cypher_priv_sg }}"
vpc_subnet_id: "{{ private_subnet_id }}"
wait: true
instance_tags:
Name: Cypher-Worker
#delete_on_termination: yes
register: ec2
那么,是否可以执行以下操作:
在配置(spot)EC2实例时,我希望以增量方式进行检查(如(40%、50%、60%、70%…),如果所有操作都失败,则创建一个按需实例我该怎么做?
我可以利用这里的功能吗?如果是,则如何进行?示例:
shell: /some/command
register: result
when: ( result is not defined ) or ( result.rc != 0 )
with_items:
- 40
- 50
- 60
- 70
- 100 # on-demand
这将使用列出的所有项目运行任务,直到成功使用其中一个项目为止
UPD:这是shell
模块的示例,我不知道ec2
模块输出结构,不要使用它。对于shell
模块,它工作正常。为什么要投反对票?这个怎么样:
- name: Create ec2 instance
ec2:
key_name: "{{ key }}"
group: "{{ group }}"
instance_type: "{{ itype }}"
image: "{{ image }}"
region: "{{ region }}"
wait: yes
wait_timeout: 500
volumes:
- device_name: /dev/xvda
volume_type: "{{ voltype }}"
volume_size: "{{ volsize }}"
monitoring: no
vpc_subnet_id: "{{ subnetid }}"
register: system
- name: Wait for ssh
wait_for: host={{ item.public_ip }} port=22 state=started
with_items:
- "{{ system.instances }}"
- name: Name the new instance
ec2_tag: resource={{ item.id }} region=eu-central-1 state=present
args:
tags:
Name: "{{ name }}"
with_items:
- "{{ system.instances }}"
您(尝试)创建实例并将其事实存储在系统中。如果需要检查system
是否实际包含所需内容,只需在定义了system.instances.id[0]时添加,或者更进一步-检查新实例是否可以在端口22上访问,如上例所示
您可以对其他任务使用这些条件检查,实现if-not逻辑——如果实例创建失败并且ssh无法访问,请创建一个按需实例
- name: Wait for ssh
wait_for: host={{ item.public_ip }} port=22 state=started
with_items:
- "{{ system.instances }}"
register: result
下一步:
when: '"ERROR" in result'
获取此错误:错误是:计算条件((ec2未定义)或(ec2.rc!=0))时出错:'dict object'没有属性'rc'
@Dawny33对于ec2模块,您应该对其输出结构使用适当的检查。我发布了shell模块的示例。您应该检查注册变量,而不是模块本身。增量检查什么?@MattSchuchardspot\u price
value您可以使用某种async/poll/register
和/或begin/rescue
来执行此操作吗?我在这里是从理论上讲的。@MattSchuchard是的,有这个功能,但它不需要超过两个rescue
块。这就是:(