---
- name: create upgrade scripts
  include: create-upgrade-scripts.yaml
  tags: create_upgrade_scripts
  when: upgrade_noop|bool or undercloud_upgrade|bool or overcloud_upgrade|bool

- block:
    - name: apply pre undercloud upgrade workarounds
      command: "{{working_dir}}/pre_undercloud_upgrade_workarounds.sh"
      when: upgrade_workarounds

    - name: upgrade undercloud
      shell: "bash {{ undercloud_upgrade_script }} &> {{ working_dir }}/undercloud_upgrade.log"
      tags: undercloud_upgrade

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

    - name: apply post undercloud upgrade workarounds
      command: "{{working_dir}}/post_undercloud_upgrade_workarounds.sh"
      when: upgrade_workarounds
  when: undercloud_upgrade|bool

- block:
    - name: apply pre overcloud upgrade prepare workarounds
      command: "{{working_dir}}/pre_overcloud_upgrade_prepare_workarounds.sh"
      when: upgrade_workarounds
      tags: overcloud_upgrade_prepare

    - include: overcloud_upgrade_prepare.yml
      tags: overcloud_upgrade_prepare

    - name: apply post overcloud upgrade prepare workarounds
      command: "{{working_dir}}/post_overcloud_upgrade_prepare_workarounds.sh"
      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
      command: "{{working_dir}}/pre_overcloud_upgrade_workarounds.sh"
      when: upgrade_workarounds
      tags: overcloud_upgrade_run

    - name: launch workload
      command: "{{ workload_launch_script }}"
      when: workload_launch_post_composable_upgrade|bool

    - include: overcloud_upgrade_run.yml
      tags: overcloud_upgrade_run

    - name: apply post overcloud upgrade workarounds
      command: "{{working_dir}}/post_overcloud_upgrade_workarounds.sh"
      when: upgrade_workarounds
      tags: overcloud_upgrade_run

    - name: apply pre overcloud upgrade converge workarounds
      command: "{{working_dir}}/pre_overcloud_converge_workarounds.sh"
      when: upgrade_workarounds
      tags: overcloud_upgrade_converge

    - include: overcloud_upgrade_converge.yml
      tags: overcloud_upgrade_converge

    - name: apply post overcloud upgrade converge workarounds
      command: "{{working_dir}}/post_overcloud_converge_workarounds.sh"
      when: upgrade_workarounds
      tags: overcloud_upgrade_converge

    - name: run controller post upgrade steps
      include: controller_post_upgrade.yml
      tags: controller_post_upgrade
      when: controller_upgrade_post|bool
  when: overcloud_upgrade|bool

