---
- name: Generate repo-setup script for overcloud upgrade
  hosts: overcloud
  tags:
    - overcloud-upgrade
  gather_facts: false
  vars:
    repo_setup_script: "repo-setup-{{ release }}.sh"
    repo_setup_log: "repo-setup-{{ release }}.log"
    # Avoid running yum update, only set up repos
    repo_setup_run_update: false
    artg_compressed_gating_repo: "${HOME}/gating_repo.tar.gz"
    # This should not be enabled because the updating of the packages occurs
    # durring the upgrade process. For general installation it's ok to have
    # this enabled, but this needs to be disabled for upgrades
    ib_gating_repo_update: false
  roles:
    - role: repo-setup
      when: containerized_overcloud_upgrade|default(false)|bool
    - role: build-test-packages
    - role: install-built-repo
      when: hostvars['undercloud']['compressed_gating_repo'] is defined and mixed_upgrade|default(false)|bool

- name: Prepare containers for Upgrade
  hosts: undercloud
  gather_facts: false
  tags:
    - overcloud-prep-containers
  roles:
    - role: overcloud-prep-containers
      # This need the new repo in place.
      update_containers: true
      # This enable us to run it even on non-containerized overcloud deployment
      # ie, ffu upgrade where deployment is on newton.
      containerized_overcloud: "{{prep_container_upgrade_run|default(false)}}"
      # Do not overwrite the deployment log if any.
      overcloud_prep_containers_log: "upgrade_overcloud_prep_containers.log"
      overcloud_prep_containers_script: "upgrade_overcloud_prep_containers.sh"
      when: containerized_overcloud_upgrade|default(false)|bool

- name: Run tripleo-upgrade role to upgrade overcloud
  hosts: undercloud
  gather_facts: true
  tags:
    - overcloud-upgrade
  tasks:
    - name: Include TripleO upgrade role
      include_role:
        name: tripleo-upgrade
      when: overcloud_upgrade|default(false)|bool or ffu_overcloud_upgrade|default(false)|bool
