---
- 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

- name: Remove unused Docker images for Docker 1.10+ migration
  shell: "docker rmi `docker images -aq`"
  # Will fail on images still in use:
  failed_when: false
  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
