2016-10-07 43 views
0

我目前为所有使用Ansible创建的实例启用termination_protection以防止意外终止控制台等现在我想能够终止与Ansible的特定实例,但我无法弄清楚如何禁用它们的终止保护。使用Ansible禁用ec2实例终止保护

这是我想会做的伎俩:在运行它时,

- name: Disable termination protection 
    ec2: 
    instance_ids: "{{ instance_ids }}" 
    region: "{{ aws_region }}" 
    termination_protection: no 

我如何过收到此错误信息:

fatal: [localhost]: FAILED! => { 
    "changed": false, 
    "failed": true, 
    "msg": "image parameter is required for new instance" 
} 

看起来Ansible是解释我的脚本实例创建请求。

有没有办法改变termination protection与另一个模块?我能想到的唯一方法是通过Ansible中的shell任务使用aws cli,但这有点冒失。

回答

3

让我们来看看source code

各国runningstopped调用startstop_instances()
restarted来电restart_instances()
这两个函数都会授予source_dest_checktermination_protection属性值。

所以你可以拨打:

- ec2: 
    instance_ids: "{{ instance_ids }}" 
    state: restarted 
    region: "{{ aws_region }}" 
    termination_protection: no 

,如果你不介意你的服务器上重新启动。

或查询当前状态与ec2_remote_facts并调用ec2模块,指出作为参数 - 这将改变termination_protection,但将保留实例的状态不变。