|
69 | 69 | costcenter: "700" |
70 | 70 | registry: 172.30.1.1:5000 |
71 | 71 | registry_user: developer |
72 | | - tasks: |
73 | | - - name: Include tasks/project-dir.yml |
74 | | - ansible.builtin.include_tasks: tasks/project-dir.yml |
75 | | - tags: |
76 | | - - always |
77 | | - |
78 | | - - name: Include variables |
79 | | - ansible.builtin.include_vars: "{{ project_dir }}/vars/{{ service }}/{{ deployment }}.yml" |
80 | | - tags: |
81 | | - - always |
82 | | - |
83 | | - - name: Include tasks/check-up-to-date.yml |
84 | | - ansible.builtin.include_tasks: tasks/check-up-to-date.yml |
85 | | - tags: |
86 | | - - always |
87 | | - |
88 | | - - name: Include deployment facts |
89 | | - ansible.builtin.include_tasks: tasks/set-deployment-facts.yml |
90 | | - tags: |
91 | | - - always |
92 | | - |
93 | | - - name: Include tasks/set-facts.yml |
94 | | - ansible.builtin.include_tasks: tasks/set-facts.yml |
95 | | - tags: |
96 | | - - always |
97 | | - |
98 | | - - name: Include extra secret vars |
99 | | - ansible.builtin.include_vars: |
100 | | - file: "{{ path_to_secrets }}/extra-vars.yml" |
101 | | - name: vault |
102 | | - tags: |
103 | | - - always |
104 | | - |
105 | | - - name: Get k8s token and check it |
106 | | - tags: |
107 | | - - always |
108 | | - block: |
109 | | - - name: Get kubeconfig token |
110 | | - ansible.builtin.command: oc whoami -t |
111 | | - register: kubeconfig_token |
112 | | - changed_when: false |
113 | | - - name: Check if tokens match |
114 | | - ansible.builtin.assert: |
115 | | - that: |
116 | | - - kubeconfig_token.stdout == api_key |
117 | | - msg: "OpenShift API token defined in vars/ does not match token from your current environment." |
118 | | - |
119 | | - - name: Push dev images to local registry |
120 | | - when: push_dev_images |
121 | | - tags: |
122 | | - - packit-service |
123 | | - - packit-worker |
124 | | - - packit-service-beat |
125 | | - block: |
126 | | - - name: Set tls-verify to false if podman is used |
127 | | - ansible.builtin.set_fact: |
128 | | - tls_verify_false: "{{ '--tls-verify=false' if 'podman' in container_engine else '' }}" |
129 | | - changed_when: false |
130 | | - - name: Login to local cluster |
131 | | - ansible.builtin.shell: "{{ container_engine }} login -u {{ registry_user }} -p $(oc whoami -t) {{ registry }} {{ tls_verify_false }}" |
132 | | - changed_when: false |
133 | | - - name: Inspect service image |
134 | | - ansible.builtin.command: "{{ container_engine }} inspect {{ image }}" |
135 | | - changed_when: false |
136 | | - - name: Tag the image with :dev |
137 | | - ansible.builtin.command: "{{ container_engine }} tag {{ image }} {{ registry }}/myproject/packit-service:dev" |
138 | | - changed_when: true |
139 | | - - name: Push the image |
140 | | - ansible.builtin.command: "{{ container_engine }} push {{ registry }}/myproject/packit-service:dev {{ tls_verify_false }}" |
141 | | - changed_when: true |
142 | | - - name: Inspect worker image |
143 | | - ansible.builtin.command: "{{ container_engine }} inspect {{ image_worker }}" |
144 | | - changed_when: false |
145 | | - - name: Tag the image with :dev |
146 | | - ansible.builtin.command: "{{ container_engine }} tag {{ image_worker }} {{ registry }}/myproject/packit-worker:dev" |
147 | | - changed_when: true |
148 | | - - name: Push the image |
149 | | - ansible.builtin.command: "{{ container_engine }} push {{ registry }}/myproject/packit-worker:dev {{ tls_verify_false }}" |
150 | | - changed_when: true |
151 | | - |
152 | | - - name: Deploy secrets |
153 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
154 | | - loop: |
155 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/secret-packit-ssh.yml.j2') }}" |
156 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/secret-packit-secrets.yml.j2') }}" |
157 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/secret-packit-config.yml.j2') }}" |
158 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/secret-sentry.yml.j2') }}" |
159 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/secret-postgres.yml.j2') }}" |
160 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/secret-aws.yml.j2') }}" |
161 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/secret-splunk.yml.j2') }}" |
162 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/secret-centpkg-sig.yml.j2') }}" |
163 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/github-app-private-key.yml.j2') }}" |
164 | | - tags: |
165 | | - - secrets |
166 | | - |
167 | | - - name: Set up sandbox namespace |
168 | | - when: with_sandbox |
169 | | - block: |
170 | | - - name: Create sandbox namespace |
171 | | - k8s: |
172 | | - resource_definition: "{{ lookup('template', '{{ project_dir }}/openshift/sandbox-namespace.yml.j2') }}" |
173 | | - host: "{{ host }}" |
174 | | - api_key: "{{ api_key }}" |
175 | | - validate_certs: "{{ validate_certs }}" |
176 | | - - name: Add edit role to service account in sandbox namespace |
177 | | - ansible.builtin.command: oc adm policy add-role-to-user edit system:serviceaccount:{{ project }}:default -n {{ sandbox_namespace }} |
178 | | - register: rolebinding |
179 | | - changed_when: "'added:' in rolebinding.stdout" |
180 | | - |
181 | | - - name: Deploy postgres |
182 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
183 | | - loop: |
184 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/postgres.yml.j2') }}" |
185 | | - tags: |
186 | | - - postgres |
187 | | - |
188 | | - - name: Deploy key-value database ({{ kv_database }}) |
189 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
190 | | - loop: |
191 | | - - "{{ lookup('file', '{{ project_dir }}/openshift/configmap-redis_like_config.yml') }}" |
192 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/{{ kv_database }}.yml.j2') }}" |
193 | | - when: with_kv_database |
194 | | - tags: |
195 | | - - kv_database |
196 | | - |
197 | | - - name: Deploy fluentd image stream and config |
198 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
199 | | - loop: |
200 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/fluentd.yml.j2') }}" |
201 | | - tags: |
202 | | - - packit-service |
203 | | - - packit-worker |
204 | | - when: with_fluentd_sidecar |
205 | | - |
206 | | - - name: Deploy packit-service |
207 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
208 | | - loop: |
209 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/packit-service.yml.j2') }}" |
210 | | - tags: |
211 | | - - packit-service |
212 | | - |
213 | | - - name: Deploy repository cache PVCs for packit-workers that serves both queues |
214 | | - vars: |
215 | | - component: "packit-worker-{{ item }}" |
216 | | - k8s: |
217 | | - namespace: "{{ sandbox_namespace }}" |
218 | | - definition: "{{ lookup('template', '{{ project_dir }}/openshift/sandcastle-volumes-for-cache.yml.j2') }}" |
219 | | - host: "{{ host }}" |
220 | | - api_key: "{{ api_key }}" |
221 | | - validate_certs: "{{ validate_certs }}" |
222 | | - loop: "{{ range(0, workers_all_tasks) | list }}" |
223 | | - tags: |
224 | | - - packit-worker |
225 | | - when: workers_all_tasks > 0 and with_repository_cache |
226 | | - |
227 | | - - name: Deploy packit-worker to serve both queues |
228 | | - vars: |
229 | | - component: packit-worker |
230 | | - queues: "short-running,long-running" |
231 | | - worker_replicas: "{{ workers_all_tasks }}" |
232 | | - worker_requests_memory: "384Mi" |
233 | | - worker_requests_cpu: "100m" |
234 | | - worker_limits_memory: "1024Mi" |
235 | | - worker_limits_cpu: "400m" |
236 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
237 | | - loop: |
238 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/packit-worker.yml.j2') }}" |
239 | | - tags: |
240 | | - - packit-worker |
241 | | - when: workers_all_tasks > 0 |
242 | | - |
243 | | - - name: Deploy packit-worker to serve short-running queue |
244 | | - vars: |
245 | | - component: packit-worker-short-running |
246 | | - queues: "short-running" |
247 | | - worker_replicas: "{{ workers_short_running }}" |
248 | | - # Short-running tasks are just interactions with different services. |
249 | | - # They should not require a lot of memory/cpu. |
250 | | - worker_requests_memory: "320Mi" |
251 | | - worker_requests_cpu: "80m" |
252 | | - worker_limits_memory: "640Mi" |
253 | | - worker_limits_cpu: "700m" |
254 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
255 | | - loop: |
256 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/packit-worker.yml.j2') }}" |
257 | | - tags: |
258 | | - - packit-worker |
259 | | - when: workers_short_running > 0 |
260 | | - |
261 | | - - name: Deploy repository cache PVCs for packit-workers that serves long-running queue |
262 | | - vars: |
263 | | - component: "packit-worker-long-running-{{ item }}" |
264 | | - k8s: |
265 | | - namespace: "{{ sandbox_namespace }}" |
266 | | - definition: "{{ lookup('template', '{{ project_dir }}/openshift/sandcastle-volumes-for-cache.yml.j2') }}" |
267 | | - host: "{{ host }}" |
268 | | - api_key: "{{ api_key }}" |
269 | | - validate_certs: "{{ validate_certs }}" |
270 | | - loop: "{{ range(0, workers_long_running) | list }}" |
271 | | - tags: |
272 | | - - packit-worker |
273 | | - when: workers_long_running > 0 and with_repository_cache |
274 | | - |
275 | | - - name: Deploy packit-worker to serve long-running queue |
276 | | - vars: |
277 | | - component: packit-worker-long-running |
278 | | - queues: "long-running" |
279 | | - worker_replicas: "{{ workers_long_running }}" |
280 | | - # cloning repos is memory intensive: glibc needs 300M+, kernel 600M+ |
281 | | - # during cloning, we need to account for git and celery worker processes |
282 | | - worker_requests_memory: "768Mi" |
283 | | - worker_requests_cpu: "100m" |
284 | | - worker_limits_memory: "2048Mi" |
285 | | - worker_limits_cpu: "600m" |
286 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
287 | | - loop: |
288 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/packit-worker.yml.j2') }}" |
289 | | - tags: |
290 | | - - packit-worker |
291 | | - when: workers_long_running > 0 |
292 | | - |
293 | | - - name: Deploy packit-service-beat |
294 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
295 | | - loop: |
296 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/packit-service-beat.yml.j2') }}" |
297 | | - when: with_beat |
298 | | - tags: |
299 | | - - packit-service-beat |
300 | | - |
301 | | - - name: Deploy dashboard |
302 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
303 | | - loop: |
304 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/dashboard.yml.j2') }}" |
305 | | - when: with_dashboard |
306 | | - tags: |
307 | | - - dashboard |
308 | | - |
309 | | - - name: Create redis-commander secrets |
310 | | - k8s: |
311 | | - namespace: "{{ project }}" |
312 | | - definition: "{{ lookup('template', '{{ project_dir }}/openshift/secret-redis-commander.yml.j2') }}" |
313 | | - host: "{{ host }}" |
314 | | - api_key: "{{ api_key }}" |
315 | | - validate_certs: "{{ validate_certs }}" |
316 | | - apply: true |
317 | | - tags: |
318 | | - - redis-commander |
319 | | - notify: |
320 | | - - Restart redis-commander deployment |
321 | | - when: with_redis_commander |
322 | | - |
323 | | - - name: Deploy redis-commander |
324 | | - vars: |
325 | | - k8s_apply: true |
326 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
327 | | - loop: |
328 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/redis-commander.yml.j2') }}" |
329 | | - when: with_redis_commander |
330 | | - tags: |
331 | | - - redis-commander |
332 | | - register: redis_commander |
333 | | - |
334 | | - - name: Deploy flower |
335 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
336 | | - loop: |
337 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/flower.yml.j2') }}" |
338 | | - when: with_flower |
339 | | - tags: |
340 | | - - flower |
341 | | - |
342 | | - - name: Deploy packit-service-fedmsg |
343 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
344 | | - loop: |
345 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/packit-service-fedmsg.yml.j2') }}" |
346 | | - tags: |
347 | | - - fedmsg |
348 | | - when: with_fedmsg |
349 | | - |
350 | | - - name: Deploy GitHub App Private Key |
351 | | - k8s: |
352 | | - namespace: "{{ project }}" |
353 | | - resource_definition: "{{ lookup('template', '{{ project_dir }}/openshift/github-app-private-key.yml.j2') }}" |
354 | | - host: "{{ host }}" |
355 | | - api_key: "{{ api_key }}" |
356 | | - validate_certs: "{{ validate_certs }}" |
357 | | - tags: |
358 | | - - tokman |
359 | | - notify: |
360 | | - - Restart tokman deployment |
361 | | - when: with_tokman |
362 | | - |
363 | | - - name: Deploy tokman |
364 | | - k8s: |
365 | | - namespace: "{{ project }}" |
366 | | - definition: "{{ lookup('template', '{{ project_dir }}/openshift/tokman.yml.j2') }}" |
367 | | - host: "{{ host }}" |
368 | | - api_key: "{{ api_key }}" |
369 | | - validate_certs: "{{ validate_certs }}" |
370 | | - tags: |
371 | | - - tokman |
372 | | - register: tokman |
373 | | - when: with_tokman |
374 | | - |
375 | | - - name: Deploy aggregating pushgateway |
376 | | - ansible.builtin.include_tasks: tasks/k8s.yml |
377 | | - loop: |
378 | | - - "{{ lookup('template', '{{ project_dir }}/openshift/pushgateway.yml.j2') }}" |
379 | | - tags: |
380 | | - - pushgateway |
381 | | - when: with_pushgateway |
382 | | - |
383 | | - - name: Create htpasswd file and deploy it as a secret |
384 | | - tags: |
385 | | - - flower |
386 | | - when: with_flower |
387 | | - block: |
388 | | - - name: Create htpasswd file |
389 | | - htpasswd: |
390 | | - path: "{{ flower_htpasswd_path }}" |
391 | | - name: "flower-boss" |
392 | | - password: "{{ vault.flower.basic_auth | regex_replace('flower-boss:', '') }}" |
393 | | - mode: 0640 |
394 | | - - name: Deploy flower-htpasswd secret |
395 | | - # Don't use tasks/k8s.yml here because the loop item is always evaluated |
396 | | - k8s: |
397 | | - namespace: "{{ project }}" |
398 | | - resource_definition: "{{ lookup('template', '{{ project_dir }}/openshift/secret-flower-htpasswd.yml.j2') }}" |
399 | | - host: "{{ host }}" |
400 | | - api_key: "{{ api_key }}" |
401 | | - validate_certs: "{{ validate_certs }}" |
402 | | - notify: |
403 | | - - Restart nginx deployment |
404 | | - |
405 | | - - name: Deploy nginx to reverse proxy the pushgateway and flower |
406 | | - k8s: |
407 | | - namespace: "{{ project }}" |
408 | | - definition: "{{ lookup('template', '{{ project_dir }}/openshift/nginx.yml.j2') }}" |
409 | | - host: "{{ host }}" |
410 | | - api_key: "{{ api_key }}" |
411 | | - validate_certs: "{{ validate_certs }}" |
412 | | - tags: |
413 | | - - pushgateway |
414 | | - register: nginx |
415 | | - when: with_pushgateway and with_flower |
416 | | - |
417 | | - - name: Wait for worker-0 to be running |
418 | | - vars: |
419 | | - pod_name: packit-worker-0 |
420 | | - ansible.builtin.include_tasks: tasks/wait_for_pod.yml |
421 | | - when: workers_all_tasks > 0 |
422 | | - |
423 | | - - name: Wait for worker-short-running-0 to be running |
424 | | - vars: |
425 | | - pod_name: packit-worker-short-running-0 |
426 | | - ansible.builtin.include_tasks: tasks/wait_for_pod.yml |
427 | | - when: workers_short_running > 0 |
428 | | - |
429 | | - - name: Wait for worker-long-running-0 to be running |
430 | | - vars: |
431 | | - pod_name: packit-worker-long-running-0 |
432 | | - ansible.builtin.include_tasks: tasks/wait_for_pod.yml |
433 | | - when: workers_long_running > 0 |
434 | | - |
435 | | - - name: Wait for deploymentconfig rollouts to complete |
436 | | - # timeout 15min to not wait indefinitely in case of a problem |
437 | | - ansible.builtin.command: timeout 15m oc rollout status -w deploy/{{ item }} |
438 | | - register: oc_rollout_status |
439 | | - changed_when: false |
440 | | - failed_when: '"successfully rolled out" not in oc_rollout_status.stdout' |
441 | | - loop: "{{ deploymentconfigs }}" |
442 | | - |
443 | | - handlers: |
444 | | - - name: Restart redis-commander deployment |
445 | | - ansible.builtin.command: oc rollout restart deploy/redis-commander |
446 | | - # Restart/rollout deployment as a reaction to config change |
447 | | - # when the deployment hasn't been changed itself. |
448 | | - changed_when: false |
449 | | - when: not redis_commander.changed |
450 | | - |
451 | | - - name: Restart tokman deployment |
452 | | - ansible.builtin.command: oc rollout restart deploy/tokman |
453 | | - # Restart/rollout deployment as a reaction to config change |
454 | | - # when the deployment hasn't been changed itself. |
455 | | - changed_when: false |
456 | | - when: not tokman.changed |
457 | | - |
458 | | - - name: Restart nginx deployment |
459 | | - ansible.builtin.command: oc rollout restart deploy/nginx |
460 | | - # Restart/rollout deployment as a reaction to config change |
461 | | - # when the deployment hasn't been changed itself. |
462 | | - changed_when: false |
463 | | - when: not nginx.changed |
| 72 | + roles: |
| 73 | + - role: deploy |
0 commit comments