|
35 | 35 | retries: 10 |
36 | 36 | delay: 30 |
37 | 37 |
|
38 | | -- name: Get list of OpenShift images from Quay.io |
39 | | - uri: |
40 | | - url: "{{ hcp_quay_api_url }}" |
41 | | - return_content: true |
42 | | - register: r_quay_response |
43 | | - |
44 | | -- name: Find the latest OpenShift image for the specified version |
45 | | - set_fact: |
46 | | - _ocp_latest_image: "{{ r_quay_response.json.tags | first | replace('multi-','') }}" |
47 | | - |
48 | | -- name: Show the latest OpenShift image |
49 | | - debug: |
50 | | - msg: "The latest OpenShift image for version {{ hcp_cluster_version }} is: {{ _ocp_latest_image.name }}" |
51 | | - |
52 | | - |
53 | 38 | - name: Log in (obtain access token) |
54 | 39 | community.okd.openshift_auth: |
55 | 40 | username: "{{ sandbox_openshift_username }}" |
|
61 | 46 | - name: Install OCP using HCP |
62 | 47 | module_defaults: |
63 | 48 | group/k8s: |
64 | | - host: "{{ sandbox_openshift_api_url }}" |
65 | | - api_key: "{{ k8s_auth_results.k8s_auth.api_key | default(sandbox_openshift_api_key) }}" |
| 49 | + host: "{{ sandbox_hcp.sandbox_openshift_api_url }}" |
| 50 | + api_key: "{{ k8s_auth_results.k8s_auth.api_key | default(sandbox_hcp.sandbox_openshift_api_key) }}" |
66 | 51 | validate_certs: false |
67 | 52 |
|
68 | 53 | block: |
| 54 | + - name: Check if x.y.z version exists |
| 55 | + when: hcp_cluster_version is match("^[0-9]+\\.[0-9]+\\.[0-9]+$") |
| 56 | + block: |
| 57 | + - name: Check if exists |
| 58 | + register: r_check_image_set |
| 59 | + kubernetes.core.k8s_info: |
| 60 | + api_version: hive.openshift.io/v1 |
| 61 | + kind: ClusterImageSet |
| 62 | + name: img{{ hcp_cluster_version }}-x86-64-appsub |
| 63 | + |
| 64 | + - name: Fail if version not available |
| 65 | + fail: |
| 66 | + msg: "Version {{ hcp_cluster_version }} not available" |
| 67 | + when: |
| 68 | + - r_check_image_set.resources | default([]) | length == 0 |
| 69 | + |
| 70 | + - name: Set releaseImage |
| 71 | + set_fact: |
| 72 | + ocp_release_image: "{{ r_check_image_set.resources[0].spec.releaseImage }}" |
| 73 | + |
| 74 | + - name: Select the latest image when x.y is specified |
| 75 | + when: hcp_cluster_version is match("^[0-9]+\\.[0-9]+$") |
| 76 | + block: |
| 77 | + - name: "Get available ClusterImageSets" |
| 78 | + kubernetes.core.k8s_info: |
| 79 | + api_version: hive.openshift.io/v1 |
| 80 | + kind: ClusterImageSet |
| 81 | + register: cis_list |
| 82 | + |
| 83 | + - name: "Filter ClusterImageSets matching version {{ hcp_cluster_version }}" |
| 84 | + set_fact: |
| 85 | + filtered_image: >- |
| 86 | + {{ |
| 87 | + cis_list.resources |
| 88 | + | selectattr('metadata.name', 'match', "img" + hcp_cluster_version|string + "\.\d+-x86-64-appsub") |
| 89 | + | sort(attribute='metadata.name', reverse=True) |
| 90 | + | first | default(None) |
| 91 | + }} |
| 92 | + |
| 93 | + - name: Fail if version not available |
| 94 | + fail: |
| 95 | + msg: "Version {{ hcp_cluster_version }} not available" |
| 96 | + when: filtered_image == "" |
| 97 | + |
| 98 | + - name: Set releaseImage |
| 99 | + set_fact: |
| 100 | + ocp_release_image: "{{ filtered_image.spec.releaseImage }}" |
| 101 | + - debug: |
| 102 | + msg: "Selected HCP version {{ ocp_release_image }}" |
| 103 | + |
69 | 104 | - name: Add the certificate definition for OAuth service |
70 | 105 | kubernetes.core.k8s: |
71 | 106 | definition: "{{ lookup('ansible.builtin.template', 'certificate.yaml') }}" |
72 | 107 | wait: true |
73 | 108 | wait_timeout: 300 |
74 | 109 | vars: |
75 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 110 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
76 | 111 |
|
77 | 112 | - name: Wait until Oauth Certificate is ready |
| 113 | + ignore_errors: true |
| 114 | + register: r_oauth |
78 | 115 | kubernetes.core.k8s_info: |
79 | 116 | api_version: cert-manager.io/v1 |
80 | 117 | kind: Certificate |
81 | 118 | name: oauth-{{ guid }} |
82 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 119 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
83 | 120 | wait: true |
84 | 121 | wait_sleep: 5 |
85 | 122 | wait_timeout: 800 |
86 | 123 | wait_condition: |
87 | 124 | type: "Ready" |
88 | 125 | status: "True" |
89 | | - |
| 126 | + |
| 127 | + - name: Restart OAuth request if it fails |
| 128 | + when: r_oauth is failed |
| 129 | + block: |
| 130 | + - name: Delete failed OAuth Certificate |
| 131 | + kubernetes.core.k8s: |
| 132 | + api_version: cert-manager.io/v1 |
| 133 | + kind: Certificate |
| 134 | + name: oauth-{{ guid }} |
| 135 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
| 136 | + state: absent |
| 137 | + |
| 138 | + - name: Add the certificate definition for OAuth service |
| 139 | + kubernetes.core.k8s: |
| 140 | + definition: "{{ lookup('ansible.builtin.template', 'certificate.yaml') }}" |
| 141 | + wait: true |
| 142 | + wait_timeout: 300 |
| 143 | + vars: |
| 144 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
| 145 | + |
| 146 | + - name: Wait until Oauth Certificate is ready |
| 147 | + kubernetes.core.k8s_info: |
| 148 | + api_version: cert-manager.io/v1 |
| 149 | + kind: Certificate |
| 150 | + name: oauth-{{ guid }} |
| 151 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
| 152 | + register: r_oauth |
| 153 | + wait: true |
| 154 | + wait_sleep: 5 |
| 155 | + wait_timeout: 800 |
| 156 | + wait_condition: |
| 157 | + type: "Ready" |
| 158 | + status: "True" |
| 159 | + |
90 | 160 | - name: Add the pull secret |
91 | 161 | kubernetes.core.k8s: |
92 | 162 | definition: "{{ lookup('ansible.builtin.template', 'pullsecret.yaml') }}" |
93 | 163 | wait: true |
94 | 164 | wait_timeout: 300 |
95 | 165 | vars: |
96 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 166 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
97 | 167 |
|
98 | 168 | - name: Set variable for kubeconfig |
99 | 169 | set_fact: |
|
107 | 177 | wait: true |
108 | 178 | wait_timeout: 300 |
109 | 179 | vars: |
110 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 180 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
111 | 181 |
|
112 | 182 | - name: Create htpasswd secret for admin and userX |
113 | 183 | include_tasks: setup_htpasswd_authentication.yml |
|
118 | 188 | wait: true |
119 | 189 | wait_timeout: 300 |
120 | 190 | vars: |
121 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 191 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
| 192 | + target_namespace: "{{ sandbox_openshift_namespace }}" |
122 | 193 |
|
123 | 194 | - name: Create the NodePool |
124 | 195 | kubernetes.core.k8s: |
125 | 196 | definition: "{{ lookup('ansible.builtin.template', 'nodepool.yaml') }}" |
126 | 197 | wait: true |
127 | 198 | wait_timeout: 300 |
128 | 199 | vars: |
129 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 200 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
130 | 201 |
|
131 | 202 | - name: Get HostedCluster |
132 | 203 | kubernetes.core.k8s_info: |
133 | 204 | api_version: hypershift.openshift.io/v1beta1 |
134 | 205 | kind: HostedCluster |
135 | 206 | name: "hcp-{{ guid }}" |
136 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 207 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
137 | 208 | register: r_hosted_cluster |
138 | 209 | retries: 120 |
139 | 210 | delay: 10 |
|
147 | 218 | api_version: v1 |
148 | 219 | kind: Secret |
149 | 220 | name: hcp-{{ guid }}-admin-kubeconfig |
150 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 221 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
151 | 222 | register: kubeadmin_secret_result |
152 | 223 |
|
153 | 224 | - name: Get the OpenShift secret |
|
156 | 227 | api_version: v1 |
157 | 228 | kind: Secret |
158 | 229 | name: hcp-{{ guid }}-kubeadmin-password |
159 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 230 | + namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}" |
160 | 231 | register: password_secret_result |
161 | 232 |
|
162 | 233 | - name: Decode the kubeconfig secret |
163 | 234 | set_fact: |
164 | 235 | kubeconfig_decoded: "{{ kubeadmin_secret_result.resources[0].data.kubeconfig | b64decode }}" |
165 | | - |
| 236 | + |
166 | 237 | - name: Decode the kubeadmin password secret |
167 | 238 | when: hcp_authentication | default('') != 'htpasswd' |
168 | 239 | set_fact: |
169 | 240 | kubeadmin_password: "{{ password_secret_result.resources[0].data.password | b64decode }}" |
170 | 241 |
|
171 | | - - name: Generate /tmp/kubeconfig |
172 | | - copy: |
173 | | - dest: /tmp/kubeconfig |
174 | | - content: "{{ kubeconfig_decoded }}" |
| 242 | +- name: Generate /tmp/kubeconfig |
| 243 | + copy: |
| 244 | + dest: /tmp/kubeconfig |
| 245 | + content: "{{ kubeconfig_decoded }}" |
175 | 246 |
|
176 | 247 | - name: Get information about the router-nodeport-default service |
177 | 248 | kubernetes.core.k8s_info: |
|
209 | 280 | wait: true |
210 | 281 | wait_timeout: 300 |
211 | 282 | vars: |
212 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 283 | + namespace: "{{ sandbox_openshift_namespace }}" |
213 | 284 |
|
214 | 285 | - name: Wait for the LoadBalancer value - workers |
215 | 286 | register: svc_apps |
216 | 287 | kubernetes.core.k8s_info: |
217 | 288 | api_version: v1 |
218 | 289 | kind: Service |
219 | 290 | name: "svc-{{ guid }}-apps" |
220 | | - namespace: "{{ hcp_ocp_namespace }}" |
| 291 | + namespace: "{{ sandbox_openshift_namespace }}" |
221 | 292 | until: svc_apps.resources[0].status.loadBalancer.ingress[0].ip | default('') != '' |
222 | 293 | retries: 10 |
223 | 294 | delay: 2 |
|
0 commit comments