Guillaume Coré
2019-01-08 5f97b6bb0615ac13d8c831559845ea5f8fcec3c8
OCP 4 destroy: fix when stack is not even present
1 files modified
33 ■■■■■ changed files
ansible/configs/ocp4-coreos-deployer/destroy_env.yml 33 ●●●●● patch | view | raw | blame | history
ansible/configs/ocp4-coreos-deployer/destroy_env.yml
@@ -16,20 +16,22 @@
        stack_name: "{{ project_tag }}"
      register: stack_facts
    - name: Grab and set stack creation_time
      set_fact:
        stack_creation_time: >-
          {{ stack_facts.ansible_facts.cloudformation[project_tag].stack_description.creation_time }}
        stack_status: >-
          {{ stack_facts.ansible_facts.cloudformation[project_tag].stack_description.stack_status }}
    - when: project_tag in stack_facts.ansible_facts.cloudformation
      block:
        - name: Grab and set stack creation_time
          set_fact:
            stack_creation_time: >-
              {{ stack_facts.ansible_facts.cloudformation[project_tag].stack_description.creation_time }}
            stack_status: >-
              {{ stack_facts.ansible_facts.cloudformation[project_tag].stack_description.stack_status }}
    - name: Backup even log for user
      shell: >-
        aws cloudtrail lookup-events
        --lookup-attributes AttributeKey=Username,AttributeValue={{ email | default( owner )}}
        --start-time {{ stack_creation_time }}
        > {{ output_dir }}/{{ env_type }}_{{ guid }}_cloudtrail_event_log.json
      when: email is defined or owner is defined
        - name: Backup even log for user
          shell: >-
            aws cloudtrail lookup-events
            --lookup-attributes AttributeKey=Username,AttributeValue={{ email | default( owner )}}
            --start-time {{ stack_creation_time }}
            > {{ output_dir }}/{{ env_type }}_{{ guid }}_cloudtrail_event_log.json
          when: email is defined or owner is defined
- name: Build inventory
  hosts: localhost
@@ -68,9 +70,12 @@
        msg: "No clientVM present"
      when: >-
        ( 'bastions' not in groups or groups.bastions | length == 0 )
        and stack_status is defined
        and stack_status == 'CREATE_COMPLETE'
    - when: stack_status == 'CREATE_COMPLETE'
    - when:
        - stack_status is defined
        - stack_status == 'CREATE_COMPLETE'
      block:
        - name: Start clientVM instance
          command: "aws ec2 start-instances --instance-ids '{{clientvm_id}}'"