---
# Determine the openshift_version to configure if none has been specified or set previously.

# Protect the installed version by default unless explicitly told not to, or given an
# openshift_version already.
- name: Use openshift_current_version fact as version to configure if already installed
  set_fact:
    openshift_version: "{{ openshift_current_version | regex_search('^\\d+\\.\\d+') }}"
  when:
  - openshift_current_version is defined
  - openshift_version is not defined or openshift_version == ""
  - openshift_protect_installed_version | bool

- name: Set openshift_version to openshift_release if undefined
  set_fact:
    openshift_version: "{{ openshift_release }}"
  when:
  - openshift_version is not defined or openshift_version == ""

- block:
  - debug:
      msg: "openshift_pkg_version was not defined. Falling back to -{{ openshift_version }}"
  - set_fact:
      # We append an '*' here because yum is not flexible.
      openshift_pkg_version: "-{{ openshift_version }}*"
  when:
  - openshift_pkg_version is not defined

- block:
  - debug:
      msg: "openshift_image_tag was not defined. Falling back to v{{ openshift_version }}"
  - set_fact:
      openshift_image_tag: "v{{ openshift_version }}"
  when: openshift_image_tag is not defined

- name: assert openshift_release in openshift_image_tag
  assert:
    that: openshift_release in openshift_image_tag
    msg: >
      openshift_image_tag must match same major version as openshift_release.
      You provided: {{ openshift_release }} and {{ openshift_image_tag }}

- name: assert openshift_release in openshift_pkg_version
  assert:
    that: openshift_release in openshift_pkg_version
    msg: >
      openshift_pkg_version must match same major version as openshift_release.
      You provided: {{ openshift_release }} and {{ openshift_pkg_version }}

# The end result of these variables is quite important so make sure they are displayed and logged:
- debug: var=openshift_release

- debug: var=openshift_image_tag

- debug: var=openshift_pkg_version

- debug: var=openshift_version
