---
- name: create undercloud update scripts
  include_tasks: create-undercloud-update-scripts.yaml
  args:
    apply:
      tags:
        - create_undercloud_update_scripts
  tags: create_undercloud_update_scripts
  when: update_noop|bool or undercloud_update|bool

- block:
    - name: apply pre undercloud update workarounds
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash pre_undercloud_update_workarounds.sh 2>&1 {{ timestamper_cmd }} > \
            pre_undercloud_update_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: updates_workarounds|bool
      tags:
        - undercloud_update

    - name: update undercloud
      shell: |
          set -o pipefail
          bash {{ undercloud_update_script }} 2>&1 {{ timestamper_cmd }} > \
            {{ working_dir }}/undercloud_update.log
      tags: undercloud_update

    - name: apply post undercloud update workarounds
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash post_undercloud_update_workarounds.sh 2>&1 {{ timestamper_cmd }} > \
            post_undercloud_update_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: updates_workarounds|bool
      tags:
        - undercloud_update

    - name: validate undercloud update
      import_tasks: ../common/undercloud_validate_upgrade.yaml
      tags: undercloud_update_validate

  when: undercloud_update|bool

- name: create overcloud update scripts
  include_tasks: create-overcloud-update-scripts.yaml
  args:
    apply:
      tags:
        - create_overcloud_update_scripts
  tags: create_overcloud_update_scripts
  when: update_noop|bool or overcloud_update|bool

- block:
    - name: apply pre overcloud update prepare workarounds
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash pre_overcloud_update_prepare_workarounds.sh 2>&1 {{ timestamper_cmd }} > \
            pre_overcloud_update_prepare_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: updates_workarounds|bool
      tags:
        - overcloud_update_prepare

    - name: Search for controller host
      set_fact:
        controller_host: "{{item.value| first}}"
      loop: "{{ groups|dict2items}}"
      when: '"controller" in item.key'

    - name: run pre-update fencing check
      import_tasks: disable_fencing.yaml

    - name: import oc update prepare tasks
      import_tasks: overcloud_update_prepare.yml
      tags:
        - overcloud_update_prepare

    - name: apply post overcloud update prepare workarounds
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash post_overcloud_update_prepare_workarounds.sh 2>&1 {{ timestamper_cmd }} > \
            post_overcloud_update_prepare_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: updates_workarounds|bool
      tags:
        - overcloud_update_prepare

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

    - name: apply pre overcloud update run workarounds
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash pre_overcloud_update_run_workarounds.sh 2>&1 {{ timestamper_cmd }} > \
            pre_overcloud_update_run_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: updates_workarounds|bool
      tags:
        - overcloud_update_run

    - name: import overcloud update run tasks
      import_tasks: overcloud_update_run.yml
      tags:
        - overcloud_update_run

    - name: apply post overcloud update run workarounds
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash post_overcloud_update_run_workarounds.sh 2>&1 {{ timestamper_cmd }} > \
            post_overcloud_update_run_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: updates_workarounds|bool
      tags:
        - overcloud_update_run

    - name: update Ceph
      include_tasks: ceph_update_run.yml
      when: ceph_osd_enabled|bool

    - name: run post-update fencing check
      import_tasks: enable_fencing.yaml

    - name: apply pre overcloud update converge workarounds
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash pre_overcloud_update_converge_workarounds.sh 2>&1 {{ timestamper_cmd }} > \
            pre_overcloud_update_converge_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: updates_workarounds|bool
      tags: overcloud_update_converge

    - name: import overcloud update converge tasks
      import_tasks: overcloud_update_converge.yml
      tags: overcloud_update_converge

    - name: apply post overcloud update converge workarounds
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash post_overcloud_update_converge_workarounds.sh 2>&1 {{ timestamper_cmd }} > \
            post_overcloud_update_converge_workarounds.log
      args:
        chdir: "{{ working_dir }}"
      when: updates_workarounds|bool
      tags: overcloud_update_converge

    - name: validate overcloud docker images/containers
      shell: |
          set -o pipefail
          source {{ undercloud_rc }}
          bash {{ overcloud_validate_images_script }} 2>&1 {{ timestamper_cmd }} > \
            {{ working_dir }}/validate_oc_images_containers.log
      when: overcloud_images_validate|bool
      tags:
        - overcloud_images_validate

    - name: import nova_actions_check tasks
      import_tasks: ../common/nova_actions_check.yml

  when: overcloud_update|bool
