summaryrefslogtreecommitdiffstats
path: root/playbooks/aws/openshift-node/terminate.yml
diff options
context:
space:
mode:
Diffstat (limited to 'playbooks/aws/openshift-node/terminate.yml')
-rw-r--r--playbooks/aws/openshift-node/terminate.yml17
1 files changed, 10 insertions, 7 deletions
diff --git a/playbooks/aws/openshift-node/terminate.yml b/playbooks/aws/openshift-node/terminate.yml
index 1c0c77eb7..40ae56f99 100644
--- a/playbooks/aws/openshift-node/terminate.yml
+++ b/playbooks/aws/openshift-node/terminate.yml
@@ -1,15 +1,15 @@
---
-- name: Populate oo_nodes_to_terminate host group if needed
+- name: Populate oo_nodes_to_terminate host group
hosts: localhost
gather_facts: no
tasks:
- - name: Evaluate oo_host_group_exp if it's set
- add_host: "name={{ item }} groups=oo_nodes_to_terminate"
- with_items: "{{ oo_host_group_exp | default('') }}"
- when: oo_host_group_exp is defined
+ - name: Evaluate oo_nodes_to_terminate
+ add_host: name={{ item }} groups=oo_nodes_to_terminate
+ with_items: oo_host_group_exp | default([])
-- name: Gather facts for instances to terminate
+- name: Gather dynamic inventory variables for hosts to terminate
hosts: oo_nodes_to_terminate
+ gather_facts: no
- name: Terminate instances
hosts: localhost
@@ -27,11 +27,12 @@
ignore_errors: yes
register: ec2_term
with_items: host_vars
+ when: "'oo_nodes_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: "item.failed and not item.msg | search(\"error: EC2ResponseError: 403 Forbidden\")"
+ when: "'oo_nodes_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
@@ -42,6 +43,7 @@
register: ec2_stop
when: item.failed
with_items: ec2_term.results
+ when: "'oo_nodes_to_terminate' in groups"
- name: Rename stopped instances
ec2_tag: resource={{ item.item.item.ec2_id }} region={{ item.item.item.ec2_region }} state=present
@@ -49,4 +51,5 @@
tags:
Name: "{{ item.item.item.ec2_tag_Name }}-terminate"
with_items: ec2_stop.results
+ when: "'oo_nodes_to_terminate' in groups"