---
- name: create undercloud upgrade scripts
  include_tasks: create-undercloud-upgrade-scripts.yaml
  args:
    apply:
      tags: create_undercloud_upgrade_scripts
  tags: create_undercloud_upgrade_scripts
  when: upgrade_noop|bool or undercloud_upgrade|bool

- block:
    - name: apply pre undercloud upgrade workarounds
      shell: |
        set -o pipefail
        bash pre_undercloud_upgrade_workarounds.sh 2>&1 {{ timestamper_cmd }} > pre_undercloud_upgrade_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds

    - name: upgrade undercloud
      shell: |
        set -o pipefail
        bash {{ undercloud_upgrade_script }} 2>&1 {{ timestamper_cmd }} > undercloud_upgrade.log
      args:
        chdir: "{{ working_dir }}"
      tags: undercloud_upgrade

    - name: validate undercloud upgrade
      import_tasks: ../common/undercloud_validate_upgrade.yaml
      tags: undercloud_upgrade_validate

    - name: apply post undercloud upgrade workarounds
      shell: |
        set -o pipefail
        bash post_undercloud_upgrade_workarounds.sh 2>&1 {{ timestamper_cmd }} > post_undercloud_upgrade_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds
  when: undercloud_upgrade|bool

- name: create overcloud upgrade scripts
  include_tasks: create-overcloud-upgrade-scripts.yaml
  args:
    apply:
      tags:
        - create_overcloud_upgrade_scripts
  tags: create_overcloud_upgrade_scripts
  when: upgrade_noop|bool or overcloud_upgrade|bool

- block:
    - name: apply pre overcloud upgrade prepare workarounds
      shell: |
        set -o pipefail
        bash pre_overcloud_upgrade_prepare_workarounds.sh 2>&1 {{ timestamper_cmd }} > pre_overcloud_upgrade_prepare_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds
      tags: overcloud_upgrade_prepare

    - import_tasks: overcloud_upgrade_prepare.yml
      tags: overcloud_upgrade_prepare

    - name: apply post overcloud upgrade prepare workarounds
      shell: |
        set -o pipefail
        bash post_overcloud_upgrade_prepare_workarounds.sh 2>&1 {{ timestamper_cmd }} > post_overcloud_upgrade_prepare_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds
      tags: overcloud_upgrade_prepare

    - name: Ensure ansible-pacemaker module is present in CI.
      yum:
        name: ansible-pacemaker
        state: latest
      when: tripleo_ci|default(false)|bool
      tags: overcloud_upgrade_run
      become: true

    - name: apply pre overcloud upgrade workarounds
      shell: |
        set -o pipefail
        bash {{ working_dir }}/pre_overcloud_upgrade_workarounds.sh 2>&1 {{ timestamper_cmd }} > pre_overcloud_upgrade_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds
      tags: overcloud_upgrade_run

    - name: launch workload
      shell: |
        set -o pipefail
        bash {{ workload_launch_script }} 2>&1 {{ timestamper_cmd }} > workload_launch.log
      args:
        chdir: "{{ working_dir }}"
      when: workload_launch|bool

    - import_tasks: overcloud_upgrade_run.yml
      tags: overcloud_upgrade_run

    - name: apply post overcloud upgrade workarounds
      shell: |
        set -o pipefail
        bash {{ working_dir }}/post_overcloud_upgrade_workarounds.sh 2>&1 {{ timestamper_cmd }} > post_overcloud_upgrade_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds
      tags: overcloud_upgrade_run

    - name: apply pre Ceph upgrade workarounds
      shell: |
        set -o pipefail
        bash pre_ceph_upgrade_workarounds.sh 2>&1 {{ timestamper_cmd }} > pre_ceph_upgrade_workarounds.log
      args:
        chdir: "{{working_dir}}"
      when: upgrade_workarounds

    - name: upgrade Ceph
      include_tasks: ceph_upgrade_run.yml
      when: ceph_osd_enabled|bool

    - name: apply post Ceph upgrade workarounds
      shell: |
        set -o pipefail
        bash post_ceph_upgrade_workarounds.sh 2>&1 {{ timestamper_cmd }} > post_ceph_upgrade_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds

    - name: apply pre overcloud upgrade converge workarounds
      shell: |
        set -o pipefail
        bash pre_overcloud_upgrade_converge_workarounds.sh 2>&1 {{ timestamper_cmd }} > pre_overcloud_upgrade_converge_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds
      tags: overcloud_upgrade_converge

    - include: overcloud_upgrade_converge.yml
      tags: overcloud_upgrade_converge

    - name: apply post overcloud upgrade converge workarounds
      shell: |
        set -o pipefail
        bash post_overcloud_upgrade_converge_workarounds.sh 2>&1 {{ timestamper_cmd }} > post_overcloud_upgrade_converge_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: upgrade_workarounds
      tags: overcloud_upgrade_converge

    - name: run controller post upgrade steps
      include_tasks: controller_post_upgrade.yml
      args:
        apply:
          tags:
            - controller_post_upgrade
      tags: controller_post_upgrade
      when: controller_upgrade_post|bool

    - import_tasks: ../common/nova_actions_check.yml

  when: overcloud_upgrade|bool
