|
@@ -15,20 +15,31 @@
|
|
|
tag-key: "kubernetes.io/cluster/{{ aws_cluster_id }}"
|
|
|
register: ec2
|
|
|
|
|
|
- - name: Stop VMs
|
|
|
+ - name: Terminate instances
|
|
|
ec2:
|
|
|
instance_ids: "{{ item.instance_id }}"
|
|
|
region: "{{ aws_region }}"
|
|
|
- state: stopped
|
|
|
+ state: absent
|
|
|
wait: no
|
|
|
with_items: "{{ ec2.instances }}"
|
|
|
- ignore_errors: true
|
|
|
+ when: not aws_use_auto_terminator | default(true)
|
|
|
|
|
|
- - name: Rename VMs
|
|
|
- ec2_tag:
|
|
|
- resource: "{{ item.instance_id }}"
|
|
|
- region: "{{ aws_region }}"
|
|
|
- tags:
|
|
|
- Name: "{{ item.tags.Name }}-terminate"
|
|
|
- when: "'-terminate' not in item.tags.Name"
|
|
|
- with_items: "{{ ec2.instances }}"
|
|
|
+ - when: aws_use_auto_terminator | default(true)
|
|
|
+ block:
|
|
|
+ - name: Stop VMs
|
|
|
+ ec2:
|
|
|
+ instance_ids: "{{ item.instance_id }}"
|
|
|
+ region: "{{ aws_region }}"
|
|
|
+ state: stopped
|
|
|
+ wait: no
|
|
|
+ with_items: "{{ ec2.instances }}"
|
|
|
+ ignore_errors: true
|
|
|
+
|
|
|
+ - name: Rename VMs
|
|
|
+ ec2_tag:
|
|
|
+ resource: "{{ item.instance_id }}"
|
|
|
+ region: "{{ aws_region }}"
|
|
|
+ tags:
|
|
|
+ Name: "{{ item.tags.Name }}-terminate"
|
|
|
+ when: "'-terminate' not in item.tags.Name"
|
|
|
+ with_items: "{{ ec2.instances }}"
|