summaryrefslogtreecommitdiffstats
path: root/roles/openshift_version/tasks/main.yml
blob: ae0f68a5b51d1965a2125b8ad5c58546c8793859 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
---
# Determine the openshift_version to configure if none has been specified or set previously.

- set_fact:
    is_containerized: "{{ openshift.common.is_containerized | default(False) | bool }}"
    is_atomic: "{{ openshift.common.is_atomic | default(False) | bool }}"

# Block attempts to install origin without specifying some kind of version information.
# This is because the latest tags for origin are usually alpha builds, which should not
# be used by default. Users must indicate what they want.
- name: Abort when we cannot safely guess what Origin image version the user wanted
  fail:
    msg: |-
      To install a containerized Origin release, you must set openshift_release or
      openshift_image_tag in your inventory to specify which version of the OpenShift
      component images to use. You may want the latest (usually alpha) releases or
      a more stable release. (Suggestion: add openshift_release="x.y" to inventory.)
  when:
  - is_containerized | bool
  - openshift.common.deployment_type == 'origin'
  - openshift_release is not defined
  - openshift_image_tag is not defined

# Normalize some values that we need in a certain format that might be confusing:
- set_fact:
    openshift_release: "{{ openshift_release[1:] }}"
  when:
  - openshift_release is defined
  - openshift_release[0] == 'v'

- set_fact:
    openshift_release: "{{ openshift_release | string }}"
  when:
  - openshift_release is defined

# Verify that the image tag is in a valid format
- when:
  - openshift_image_tag is defined
  - openshift_image_tag != "latest"
  block:

  # Verifies that when the deployment type is origin the version:
  # - starts with a v
  # - Has 3 integers seperated by dots
  # It also allows for optional trailing data which:
  # - must start with a dash
  # - may contain numbers, letters, dashes and dots.
  - name: (Origin) Verify openshift_image_tag is valid
    when: openshift.common.deployment_type == 'origin'
    assert:
      that:
      - "{{ openshift_image_tag|match('(^v?\\d+\\.\\d+\\.\\d+(-[\\w\\-\\.]*)?$)') }}"
      msg: |-
        openshift_image_tag must be in the format v#.#.#[-optional.#]. Examples: v1.2.3, v3.5.1-alpha.1
        You specified openshift_image_tag={{ openshift_image_tag }}

  # Verifies that when the deployment type is openshift-enterprise the version:
  # - starts with a v
  # - Has at least 2 integers seperated by dots
  # It also allows for optional trailing data which:
  # - must start with a dash
  # - may contain numbers
  # - may containe dots (https://github.com/openshift/openshift-ansible/issues/5192)
  #
  - name: (Enterprise) Verify openshift_image_tag is valid
    when: openshift.common.deployment_type == 'openshift-enterprise'
    assert:
      that:
      - "{{ openshift_image_tag|match('(^v\\d+\\.\\d+(\\.\\d+)*(-\\d+(\\.\\d+)*)?$)') }}"
      msg: |-
        openshift_image_tag must be in the format v#.#[.#[.#]]. Examples: v1.2, v3.4.1, v3.5.1.3,
        v3.5.1.3.4, v1.2-1, v1.2.3-4, v1.2.3-4.5, v1.2.3-4.5.6
        You specified openshift_image_tag={{ openshift_image_tag }}

# Make sure we copy this to a fact if given a var:
- set_fact:
    openshift_version: "{{ openshift_version | string }}"
  when: openshift_version is defined

# Protect the installed version by default unless explicitly told not to, or given an
# openshift_version already.
- name: Use openshift.common.version fact as version to configure if already installed
  set_fact:
    openshift_version: "{{ openshift.common.version }}"
  when:
  - openshift.common.version is defined
  - openshift_version is not defined or openshift_version == ""
  - openshift_protect_installed_version | bool

# The rest of these tasks should only execute on
# masters and nodes as we can verify they have subscriptions
- when:
  - inventory_hostname in groups['oo_masters_to_config'] or inventory_hostname in groups['oo_nodes_to_config']
  block:
  - name: Set openshift_version for rpm installation
    include_tasks: set_version_rpm.yml
    when: not is_containerized | bool

  - name: Set openshift_version for containerized installation
    include_tasks: set_version_containerized.yml
    when: is_containerized | bool

  - block:
    - name: Get available {{ openshift_service_type}} version
      repoquery:
        name: "{{ openshift_service_type}}"
        ignore_excluders: true
      register: rpm_results
    - fail:
        msg: "Package {{ openshift_service_type}} not found"
      when: not rpm_results.results.package_found
    - set_fact:
        openshift_rpm_version: "{{ rpm_results.results.versions.available_versions.0 | default('0.0', True) }}"
    - name: Fail if rpm version and docker image version are different
      fail:
        msg: "OCP rpm version {{ openshift_rpm_version }} is different from OCP image version {{ openshift_version }}"
      # Both versions have the same string representation
      when:
      - openshift_rpm_version != openshift_version
      # if openshift_pkg_version or openshift_image_tag is defined, user gives a permission the rpm and docker image versions can differ
      - openshift_pkg_version is not defined
      - openshift_image_tag is not defined
    when:
    - is_containerized | bool
    - not is_atomic | bool

  # Warn if the user has provided an openshift_image_tag but is not doing a containerized install
  # NOTE: This will need to be modified/removed for future container + rpm installations work.
  - name: Warn if openshift_image_tag is defined when not doing a containerized install
    debug:
      msg: >
        openshift_image_tag is used for containerized installs. If you are trying to
        specify an image for a non-container install see oreg_url or oreg_url_master or oreg_url_node.
    when:
    - not is_containerized | bool
    - openshift_image_tag is defined

  # At this point we know openshift_version is set appropriately. Now we set
  # openshift_image_tag and openshift_pkg_version, so all roles can always assume
  # each of this variables *will* be set correctly and can use them per their
  # intended purpose.

  - block:
    - debug:
        msg: "openshift_image_tag was not defined. Falling back to v{{ openshift_version }}"

    - set_fact:
        openshift_image_tag: v{{ openshift_version }}

    when: openshift_image_tag is not defined

  - block:
    - debug:
        msg: "openshift_pkg_version was not defined. Falling back to -{{ openshift_version }}"

    - set_fact:
        openshift_pkg_version: -{{ openshift_version }}

    when:
    - openshift_pkg_version is not defined
    - openshift_upgrade_target is not defined

  - fail:
      msg: openshift_version role was unable to set openshift_version
    name: Abort if openshift_version was not set
    when: openshift_version is not defined

  - fail:
      msg: openshift_version role was unable to set openshift_image_tag
    name: Abort if openshift_image_tag was not set
    when: openshift_image_tag is not defined

  - fail:
      msg: openshift_version role was unable to set openshift_pkg_version
    name: Abort if openshift_pkg_version was not set
    when:
    - openshift_pkg_version is not defined
    - openshift_upgrade_target is not defined


  - fail:
      msg: "No OpenShift version available; please ensure your systems are fully registered and have access to appropriate yum repositories."
    name: Abort if openshift_pkg_version was not set
    when:
    - not is_containerized | bool
    - openshift_version == '0.0'

  # We can't map an openshift_release to full rpm version like we can with containers; make sure
  # the rpm version we looked up matches the release requested and error out if not.
  - name: For an RPM install, abort when the release requested does not match the available version.
    when:
    - not is_containerized | bool
    - openshift_release is defined
    assert:
      that:
      - openshift_version.startswith(openshift_release) | bool
      msg: |-
        You requested openshift_release {{ openshift_release }}, which is not matched by
        the latest OpenShift RPM we detected as {{ openshift_service_type }}-{{ openshift_version }}
        on host {{ inventory_hostname }}.
        We will only install the latest RPMs, so please ensure you are getting the release
        you expect. You may need to adjust your Ansible inventory, modify the repositories
        available on the host, or run the appropriate OpenShift upgrade playbook.

  # The end result of these three variables is quite important so make sure they are displayed and logged:
  - debug: var=openshift_release

  - debug: var=openshift_image_tag

  - debug: var=openshift_pkg_version