- name: create a comptatible deployment scripts from oooq
  include: ../upgrade/use_oooq.yaml
  tags: use_oooq
  when: use_oooq|bool

- name: make a copy of the initial overcloud deploy script
  copy:
    remote_src: yes
    src: "{{ overcloud_deploy_script }}"
    dest: "{{ overcloud_deploy_script }}.orig"

- name: create ffu upgrade workaround scripts
  template:
    src: fast-forward-upgrade/workarounds.sh.j2
    dest: "{{working_dir}}/{{ item }}.sh"
    mode: 0775
  with_items:
     - 'post_ffu_undercloud_upgrade_workarounds'
     - 'pre_ffu_update_stack_outputs_workarounds'
     - 'pre_ffu_download_config_workarounds'
     - 'pre_ffu_upgrade_playbook_workarounds'
     - 'pre_ffu_upgrade_steps_playbook_workarounds'
     - 'pre_ffu_deploy_steps_playbook_workarounds'
  when: ffu_upgrade_workarounds

- name: register is_upstream variable
  shell: |
    rpm -q openstack-tripleo-heat-templates | grep '\.el[[:digit:]]\.'
  failed_when: false
  register: is_upstream

- name: Check if overcoud deployed with pacemaker
  shell: |
    source {{ undercloud_rc }}
    openstack stack output show overcloud EnabledServices | grep 'pacemaker'
  failed_when: false
  register: pacemaker_present

- name: set deployment_with_ha fact
  set_fact:
    deployment_with_ha: "{{ is_upstream.rc == 0 and pacemaker_present.rc == 0 }}"

- name: create ffu overcloud upgrade scripts
  include: ../upgrade/step_upgrade.yml
  loop_control:
    loop_var: ugstage
  with_items:
    - step: "FFU update stack outputs"
      script: "{{ working_dir }}/ffu_update_stack_outputs.sh"
      environment_file:
        - "{% if upstream_container_images %}{{ tht_directory }}/environments/docker.yaml{% endif %}"
        - "{% if upstream_container_images and deployment_with_ha %}{{ tht_directory }}/environments/docker-ha.yaml{% endif %}"
        - "{{ working_dir}}/{{ container_registry_file }}"
        - "{{ tht_directory }}/environments/fast-forward-upgrade.yaml"
        - "{{ tht_directory }}/environments/config-download-environment.yaml"
