main.yml 7.0 KB

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