main.yml 8.9 KB

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