---
# input variables:
# - openshift.common.service_type
# - openshift.common.is_containerized
# - docker_upgrade_nuke_images
# - docker_version
# - skip_docker_restart

- name: Check Docker image count
  shell: "docker images -aq | wc -l"
  register: docker_image_count

- debug: var=docker_image_count.stdout

# TODO(jchaloup): put all docker_upgrade_nuke_images into a block with only one condition
- name: Remove all containers and images
  script: nuke_images.sh
  register: nuke_images_result
  when: docker_upgrade_nuke_images is defined and docker_upgrade_nuke_images | bool

- name: Check Docker image count
  shell: "docker images -aq | wc -l"
  register: docker_image_count
  when: docker_upgrade_nuke_images is defined and docker_upgrade_nuke_images | bool

- debug: var=docker_image_count.stdout
  when: docker_upgrade_nuke_images is defined and docker_upgrade_nuke_images | bool

- service:
    name: docker
    state: stopped
  register: l_openshift_node_upgrade_docker_stop_result
  until: not l_openshift_node_upgrade_docker_stop_result | failed
  retries: 3
  delay: 30

- name: Upgrade Docker
  package: name=docker{{ '-' + docker_version }} state=present

# starting docker happens back in ../main.yml where it calls ../restart.yml
