docker_upgrade_check.yml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_installed }} --qf '%{version}' docker"
  16. register: curr_docker_version
  17. retries: 4
  18. until: curr_docker_version | succeeded
  19. changed_when: false
  20. - name: Get latest available version of Docker
  21. command: >
  22. {{ repoquery_cmd }} --qf '%{version}' "docker"
  23. register: avail_docker_version
  24. retries: 4
  25. until: avail_docker_version | succeeded
  26. # Don't expect docker rpm to be available on hosts that don't already have it installed:
  27. when: pkg_check.rc == 0
  28. failed_when: false
  29. changed_when: false
  30. - fail:
  31. msg: This playbook requires access to Docker 1.12 or later
  32. # Disable the 1.12 requirement if the user set a specific Docker version
  33. 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.12','<')))
  34. # Default l_docker_upgrade to False, we'll set to True if an upgrade is required:
  35. - set_fact:
  36. l_docker_upgrade: False
  37. # Make sure a docker_version is set if none was requested:
  38. - set_fact:
  39. docker_version: "{{ avail_docker_version.stdout }}"
  40. when: pkg_check.rc == 0 and docker_version is not defined
  41. - name: Flag for Docker upgrade if necessary
  42. set_fact:
  43. l_docker_upgrade: True
  44. when: pkg_check.rc == 0 and curr_docker_version.stdout | version_compare(docker_version,'<')
  45. # Additional checks for Atomic hosts:
  46. - name: Determine available Docker
  47. shell: "rpm -q --queryformat '---\ncurr_version: %{VERSION}\navail_version: \n' docker"
  48. register: g_atomic_docker_version_result
  49. when: openshift.common.is_atomic | bool
  50. - set_fact:
  51. l_docker_version: "{{ g_atomic_docker_version_result.stdout | from_yaml }}"
  52. when: openshift.common.is_atomic | bool
  53. - fail:
  54. msg: This playbook requires access to Docker 1.12 or later
  55. when: openshift.common.is_atomic | bool and l_docker_version.avail_version | default(l_docker_version.curr_version, true) | version_compare('1.12','<')