upgrade_check.yml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ---
  2. # This snippet determines if a Docker upgrade is required by checking the inventory
  3. # variables, the available packages, and sets l_docker_upgrade to True if so.
  4. - set_fact:
  5. docker_upgrade: True
  6. when: docker_upgrade is not defined
  7. - name: Check if Docker is installed
  8. command: rpm -q docker
  9. args:
  10. warn: no
  11. register: pkg_check
  12. failed_when: pkg_check.rc > 1
  13. changed_when: no
  14. - name: Get current version of Docker
  15. command: "{{ repoquery_cmd }} --installed --qf '%{version}' docker"
  16. register: curr_docker_version
  17. changed_when: false
  18. - name: Get latest available version of Docker
  19. command: >
  20. {{ repoquery_cmd }} --qf '%{version}' "docker"
  21. register: avail_docker_version
  22. # Don't expect docker rpm to be available on hosts that don't already have it installed:
  23. when: pkg_check.rc == 0
  24. failed_when: false
  25. changed_when: false
  26. - fail:
  27. msg: This playbook requires access to Docker 1.10 or later
  28. # Disable the 1.10 requirement if the user set a specific Docker version
  29. when: docker_version is not defined and (docker_upgrade is not defined or docker_upgrade | bool == True) and (pkg_check.rc == 0 and (avail_docker_version.stdout == "" or avail_docker_version.stdout | version_compare('1.10','<')))
  30. # Default l_docker_upgrade to False, we'll set to True if an upgrade is required:
  31. - set_fact:
  32. l_docker_upgrade: False
  33. # Make sure a docker_version is set if none was requested:
  34. - set_fact:
  35. docker_version: "{{ avail_docker_version.stdout }}"
  36. when: pkg_check.rc == 0 and docker_version is not defined
  37. - name: Flag for Docker upgrade if necessary
  38. set_fact:
  39. l_docker_upgrade: True
  40. when: pkg_check.rc == 0 and curr_docker_version.stdout | version_compare(docker_version,'<')
  41. - name: Flag to delete all images prior to upgrade if crossing Docker 1.10 boundary
  42. set_fact:
  43. docker_upgrade_nuke_images: True
  44. when: l_docker_upgrade | bool and docker_upgrade_nuke_images is not defined and curr_docker_version.stdout | version_compare('1.10','<') and docker_version | version_compare('1.10','>=')