2016-10-07 45 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,但將保留實例的狀態不變。