main.yml 8.4 KB

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