---
# Generate a script from templates. These are scripts
# rather than additional ansible tasks so that they can be run
# manually from the undercloud host.
- name: Create overcloud delete script
  template:
    src: "{{ delete_script }}"
    dest: "{{ working_dir }}/overcloud-delete.sh"
    mode: 0755
  tags:
    - overcloud-scripts

- when: step_delete_overcloud|bool
  block:
    - name: Delete the overcloud
      shell: >
        set -o pipefail &&
        {{ working_dir }}/overcloud-delete.sh 2>&1 {{ timestamper_cmd }} > {{ delete_log }}
      tags:
        - overcloud-delete

    - name: check for delete command to complete or fail
      shell: |
          source {{ working_dir }}/stackrc
          openstack stack show $(cat {{ working_dir }}/overcloud_id) -f yaml
      delay: "{{ delete_check_delay }}"
      retries: "{{ delete_check_retries }}"
      until: heat_stack_show.stdout.find('DELETE_COMPLETE') != -1
      register: heat_stack_show
      tags:
        - overcloud-delete
