main.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. ---
  2. # Determine the openshift_version to configure if none has been specified or set previously.
  3. - set_fact:
  4. is_containerized: "{{ openshift.common.is_containerized | default(False) | bool }}"
  5. is_atomic: "{{ openshift.common.is_atomic | default(False) | bool }}"
  6. # Block attempts to install origin without specifying some kind of version information.
  7. # This is because the latest tags for origin are usually alpha builds, which should not
  8. # be used by default. Users must indicate what they want.
  9. - name: Abort when we cannot safely guess what Origin image version the user wanted
  10. fail:
  11. msg: |-
  12. To install a containerized Origin release, you must set openshift_release or
  13. openshift_image_tag in your inventory to specify which version of the OpenShift
  14. component images to use. You may want the latest (usually alpha) releases or
  15. a more stable release. (Suggestion: add openshift_release="x.y" to inventory.)
  16. when:
  17. - is_containerized | bool
  18. - openshift.common.deployment_type == 'origin'
  19. - openshift_release is not defined
  20. - openshift_image_tag is not defined
  21. # Normalize some values that we need in a certain format that might be confusing:
  22. - set_fact:
  23. openshift_release: "{{ openshift_release[1:] }}"
  24. when:
  25. - openshift_release is defined
  26. - openshift_release[0] == 'v'
  27. - set_fact:
  28. openshift_release: "{{ openshift_release | string }}"
  29. when: openshift_release is defined
  30. # Verify that the image tag is in a valid format
  31. - when:
  32. - openshift_image_tag is defined
  33. - openshift_image_tag != "latest"
  34. block:
  35. # Verifies that when the deployment type is origin the version:
  36. # - starts with a v
  37. # - Has 3 integers seperated by dots
  38. # It also allows for optional trailing data which:
  39. # - must start with a dash
  40. # - may contain numbers, letters, dashes and dots.
  41. - name: (Origin) Verify openshift_image_tag is valid
  42. when: openshift.common.deployment_type == 'origin'
  43. assert:
  44. that:
  45. - "{{ openshift_image_tag|match('(^v?\\d+\\.\\d+\\.\\d+(-[\\w\\-\\.]*)?$)') }}"
  46. msg: |-
  47. openshift_image_tag must be in the format v#.#.#[-optional.#]. Examples: v1.2.3, v3.5.1-alpha.1
  48. You specified openshift_image_tag={{ openshift_image_tag }}
  49. # Verifies that when the deployment type is openshift-enterprise the version:
  50. # - starts with a v
  51. # - Has at least 2 integers seperated by dots
  52. # It also allows for optional trailing data which:
  53. # - must start with a dash
  54. # - may contain numbers
  55. - name: (Enterprise) Verify openshift_image_tag is valid
  56. when: openshift.common.deployment_type == 'openshift-enterprise'
  57. assert:
  58. that:
  59. - "{{ openshift_image_tag|match('(^v\\d+\\.\\d+[\\.\\d+]*(-\\d+)?$)') }}"
  60. msg: |-
  61. openshift_image_tag must be in the format v#.#[.#[.#]]. Examples: v1.2, v3.4.1, v3.5.1.3, v1.2-1, v1.2.3-4
  62. You specified openshift_image_tag={{ openshift_image_tag }}
  63. # Make sure we copy this to a fact if given a var:
  64. - set_fact:
  65. openshift_version: "{{ openshift_version | string }}"
  66. when: openshift_version is defined
  67. # Protect the installed version by default unless explicitly told not to, or given an
  68. # openshift_version already.
  69. - name: Use openshift.common.version fact as version to configure if already installed
  70. set_fact:
  71. openshift_version: "{{ openshift.common.version }}"
  72. when:
  73. - openshift.common.version is defined
  74. - openshift_version is not defined
  75. - openshift_protect_installed_version | bool
  76. - name: Set openshift_version for rpm installation
  77. include: set_version_rpm.yml
  78. when: not is_containerized | bool
  79. - name: Set openshift_version for containerized installation
  80. include: set_version_containerized.yml
  81. when: is_containerized | bool
  82. - block:
  83. - name: Get available {{ openshift.common.service_type}} version
  84. repoquery:
  85. name: "{{ openshift.common.service_type}}"
  86. ignore_excluders: true
  87. register: rpm_results
  88. - fail:
  89. msg: "Package {{ openshift.common.service_type}} not found"
  90. when: not rpm_results.results.package_found
  91. - set_fact:
  92. openshift_rpm_version: "{{ rpm_results.results.versions.available_versions.0 | default('0.0', True) }}"
  93. - name: Fail if rpm version and docker image version are different
  94. fail:
  95. msg: "OCP rpm version {{ openshift_rpm_version }} is different from OCP image version {{ openshift_version }}"
  96. # Both versions have the same string representation
  97. when: openshift_rpm_version != openshift_version
  98. when:
  99. - is_containerized | bool
  100. - not is_atomic | bool
  101. # Warn if the user has provided an openshift_image_tag but is not doing a containerized install
  102. # NOTE: This will need to be modified/removed for future container + rpm installations work.
  103. - name: Warn if openshift_image_tag is defined when not doing a containerized install
  104. debug:
  105. msg: >
  106. openshift_image_tag is used for containerized installs. If you are trying to
  107. specify an image for a non-container install see oreg_url.
  108. when:
  109. - not is_containerized | bool
  110. - openshift_image_tag is defined
  111. # At this point we know openshift_version is set appropriately. Now we set
  112. # openshift_image_tag and openshift_pkg_version, so all roles can always assume
  113. # each of this variables *will* be set correctly and can use them per their
  114. # intended purpose.
  115. - block:
  116. - debug:
  117. msg: "openshift_image_tag was not defined. Falling back to v{{ openshift_version }}"
  118. - set_fact:
  119. openshift_image_tag: v{{ openshift_version }}
  120. when: openshift_image_tag is not defined
  121. - block:
  122. - debug:
  123. msg: "openshift_pkg_version was not defined. Falling back to -{{ openshift_version }}"
  124. - set_fact:
  125. openshift_pkg_version: -{{ openshift_version }}
  126. when: openshift_pkg_version is not defined
  127. - fail:
  128. msg: openshift_version role was unable to set openshift_version
  129. name: Abort if openshift_version was not set
  130. when: openshift_version is not defined
  131. - fail:
  132. msg: openshift_version role was unable to set openshift_image_tag
  133. name: Abort if openshift_image_tag was not set
  134. when: openshift_image_tag is not defined
  135. - fail:
  136. msg: openshift_version role was unable to set openshift_pkg_version
  137. name: Abort if openshift_pkg_version was not set
  138. when: openshift_pkg_version is not defined
  139. - fail:
  140. msg: "No OpenShift version available; please ensure your systems are fully registered and have access to appropriate yum repositories."
  141. name: Abort if openshift_pkg_version was not set
  142. when:
  143. - not is_containerized | bool
  144. - openshift_version == '0.0'
  145. # We can't map an openshift_release to full rpm version like we can with containers; make sure
  146. # the rpm version we looked up matches the release requested and error out if not.
  147. - name: For an RPM install, abort when the release requested does not match the available version.
  148. when:
  149. - not is_containerized | bool
  150. - openshift_release is defined
  151. assert:
  152. that:
  153. - openshift_version.startswith(openshift_release) | bool
  154. msg: |-
  155. You requested openshift_release {{ openshift_release }}, which is not matched by
  156. the latest OpenShift RPM we detected as {{ openshift.common.service_type }}-{{ openshift_version }}
  157. on host {{ inventory_hostname }}.
  158. We will only install the latest RPMs, so please ensure you are getting the release
  159. you expect. You may need to adjust your Ansible inventory, modify the repositories
  160. available on the host, or run the appropriate OpenShift upgrade playbook.
  161. # The end result of these three variables is quite important so make sure they are displayed and logged:
  162. - debug: var=openshift_release
  163. - debug: var=openshift_image_tag
  164. - debug: var=openshift_pkg_version