---
# Sanity checks to ensure the role will complete and provide helpful error
# messages for common problems.

- name: Error out if Docker pre-installed but too old
  fail:
    msg: "Docker {{ curr_docker_version.stdout }} is installed, but >= 1.9.1 is required."
  when:
  - not (curr_docker_version is skipped)
  - curr_docker_version.stdout != ''
  - curr_docker_version.stdout is version_compare('1.9.1', '<')
  - not (docker_version is defined)

- name: Error out if requested Docker is too old
  fail:
    msg: "Docker {{ docker_version }} requested, but >= 1.9.1 is required."
  when:
  - docker_version is defined
  - docker_version is version_compare('1.9.1', '<')

# If a docker_version was requested, sanity check that we can install or upgrade to it, and
# no downgrade is required.
- name: Fail if Docker version requested but downgrade is required
  fail:
    msg: "Docker {{ curr_docker_version.stdout }} is installed, but version {{ docker_version }} was requested."
  when:
  - not (curr_docker_version is skipped)
  - curr_docker_version.stdout != ''
  - docker_version is defined
  - curr_docker_version.stdout is version_compare(docker_version, '>')

# This involves an extremely slow migration process, users should instead run the
# Docker 1.10 upgrade playbook to accomplish this.
- name: Error out if attempting to upgrade Docker across the 1.10 boundary
  fail:
    msg: "Cannot upgrade Docker to >= 1.10, please upgrade or remove Docker manually, or use the Docker upgrade playbook if OpenShift is already installed."
  when:
  - not (curr_docker_version is skipped)
  - curr_docker_version.stdout != ''
  - curr_docker_version.stdout is version_compare('1.10', '<')
  - docker_version is defined
  - docker_version is version_compare('1.10', '>=')
