瀏覽代碼

test ci: add an option to terminate VMs instead of stopping

Vadim Rutkovsky 6 年之前
父節點
當前提交
bb9e8531af
共有 2 個文件被更改,包括 25 次插入11 次删除
  1. 22 11
      test/ci/deprovision.yml
  2. 3 0
      test/ci/vars.yml.sample

+ 22 - 11
test/ci/deprovision.yml

@@ -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 }}"

+ 3 - 0
test/ci/vars.yml.sample

@@ -1,5 +1,8 @@
 ---
 vm_prefix: "ci_test"
+#aws_use_auto_terminator is set to True by default, as rh-dev account doesn't have permission
+# to terminate instances. These should be stopped and renamed to include 'terminate' instead
+#aws_use_auto_terminator: false
 
 type: aws
 aws_user: "ec2-user"