docker_upgrade_check.yml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 is 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 is 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:
  34. - docker_version is not defined
  35. - docker_upgrade is not defined or docker_upgrade | bool == True
  36. - (pkg_check.rc == 0 and (avail_docker_version.stdout == "" or avail_docker_version.stdout is version_compare('1.12','<')))
  37. # Default l_docker_upgrade to False, we'll set to True if an upgrade is required:
  38. - set_fact:
  39. l_docker_upgrade: False
  40. # Make sure a docker_version is set if none was requested:
  41. - set_fact:
  42. docker_version: "{{ avail_docker_version.stdout }}"
  43. when: pkg_check.rc == 0 and docker_version is not defined
  44. - name: Flag for Docker upgrade if necessary
  45. set_fact:
  46. l_docker_upgrade: True
  47. when:
  48. - pkg_check.rc == 0
  49. - curr_docker_version.stdout is version_compare(docker_version,'<')
  50. # Additional checks for Atomic hosts:
  51. - name: Determine available Docker
  52. shell: "rpm -q --queryformat '---\ncurr_version: %{VERSION}\navail_version: \n' docker"
  53. register: g_atomic_docker_version_result
  54. when: openshift.common.is_atomic | bool
  55. - set_fact:
  56. l_docker_version: "{{ g_atomic_docker_version_result.stdout | from_yaml }}"
  57. when: openshift.common.is_atomic | bool
  58. - fail:
  59. msg: This playbook requires access to Docker 1.12 or later
  60. when:
  61. - openshift.common.is_atomic | bool
  62. - l_docker_version.avail_version | default(l_docker_version.curr_version, true) is version_compare('1.12','<')