diff options
author | Jason DeTiberus <jdetiber@redhat.com> | 2015-04-16 22:44:12 -0400 |
---|---|---|
committer | Jason DeTiberus <jdetiber@redhat.com> | 2015-04-20 23:55:56 -0400 |
commit | ba5ae4dbc7741af1963df36fd92bcd0af03c6b4f (patch) | |
tree | b2ed4f9e37b793a0291d9cf435db6f103e24c2f3 /playbooks/aws/terminate.yml | |
parent | 96dd0ab929b7f391eee9b23209aa377537114b72 (diff) | |
download | openshift-ba5ae4dbc7741af1963df36fd92bcd0af03c6b4f.tar.gz openshift-ba5ae4dbc7741af1963df36fd92bcd0af03c6b4f.tar.bz2 openshift-ba5ae4dbc7741af1963df36fd92bcd0af03c6b4f.tar.xz openshift-ba5ae4dbc7741af1963df36fd92bcd0af03c6b4f.zip |
aws terminate playbook improvements
- Reduce duplication in terminate playbooks between openshift-master and
openshift-node (they both now just include playbooks/aws/terminate.yml
- update openshift-cluster terminate playbook to include the new shared
terminate playbook, also delete all cluster hosts at once instead of
treating masters and nodes differently.
- remove env, host-type and env-host-type tags from instance before
terminating (since most users can't terminate, we are mostly just renaming
instances to -terminate and stopping them, so this prevents "terminated" hosts
from being returned by the dynamic inventory, at least after the cache is
refreshed)
Diffstat (limited to 'playbooks/aws/terminate.yml')
-rw-r--r-- | playbooks/aws/terminate.yml | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/playbooks/aws/terminate.yml b/playbooks/aws/terminate.yml new file mode 100644 index 000000000..e9767b260 --- /dev/null +++ b/playbooks/aws/terminate.yml @@ -0,0 +1,64 @@ +--- +- name: Populate oo_hosts_to_terminate host group + hosts: localhost + gather_facts: no + tasks: + - name: Evaluate oo_hosts_to_terminate + add_host: name={{ item }} groups=oo_hosts_to_terminate + with_items: oo_host_group_exp | default([]) + +- name: Gather dynamic inventory variables for hosts to terminate + hosts: oo_hosts_to_terminate + gather_facts: no + +- name: Terminate instances + hosts: localhost + connection: local + gather_facts: no + vars: + host_vars: "{{ hostvars + | oo_select_keys(groups['oo_hosts_to_terminate']) }}" + tasks: + - name: Remove tags from instances + ec2_tag: resource={{ item.ec2_id }} region={{ item.ec2_region }} state=absent + args: + tags: + env: "{{ item['ec2_tag_env'] }}" + host-type: "{{ item['ec2_tag_host-type'] }}" + env-host-type: "{{ item['ec2_tag_env-host-type'] }}" + with_items: host_vars + when: "'oo_hosts_to_terminate' in groups" + + - name: Terminate instances + ec2: + state: absent + instance_ids: ["{{ item.ec2_id }}"] + region: "{{ item.ec2_region }}" + ignore_errors: yes + register: ec2_term + with_items: host_vars + when: "'oo_hosts_to_terminate' in groups" + + # Fail if any of the instances failed to terminate with an error other + # than 403 Forbidden + - fail: msg=Terminating instance {{ item.item.ec2_id }} failed with message {{ item.msg }} + when: "'oo_hosts_to_terminate' in groups and item.failed and not item.msg | search(\"error: EC2ResponseError: 403 Forbidden\")" + with_items: ec2_term.results + + - name: Stop instance if termination failed + ec2: + state: stopped + instance_ids: ["{{ item.item.ec2_id }}"] + region: "{{ item.item.ec2_region }}" + register: ec2_stop + when: item.failed + with_items: ec2_term.results + when: "'oo_hosts_to_terminate' in groups" + + - name: Rename stopped instances + ec2_tag: resource={{ item.item.item.ec2_id }} region={{ item.item.item.ec2_region }} state=present + args: + tags: + Name: "{{ item.item.item.ec2_tag_Name }}-terminate" + with_items: ec2_stop.results + when: "'oo_hosts_to_terminate' in groups" |