Create a role to run jobs in OpenShift

Inspired by Koschei's `koschei/job` role.
Adapt the MirrorManager move-to-archive job to it.

Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
This commit is contained in:
Aurélien Bompard
2024-08-06 07:49:53 +02:00
parent be65fcee91
commit 5778e0d999
4 changed files with 38 additions and 22 deletions

View File

@@ -0,0 +1,2 @@
os_app: "{{app}}"
template: job.yml

View File

@@ -0,0 +1,30 @@
- name: Validate the job name {{ name }}
assert:
that:
- name is defined
fail_msg: "The 'name' variable is not defined"
- name: Validate the command {{ command }}
assert:
that:
- command is defined
fail_msg: "The 'command' variable is not defined"
- name: Copy job template to a temporary file
template:
src: "{{roles_path}}/openshift-apps/{{app}}/templates/{{template}}"
dest: "/etc/openshift_apps/{{app}}/job-{{name}}.yml"
- name: Delete previous job (if any)
shell: oc -n {{os_app}} delete --ignore-not-found=true -f /etc/openshift_apps/{{app}}/job-{{name}}.yml
- name: Start job
shell: oc -n {{os_app}} create -f /etc/openshift_apps/{{app}}/job-{{name}}.yml
- debug:
msg: "Job started. You can watch the logs with: oc -n {{os_app}} logs -f job/job-{{name}}"
- debug:
msg: "You can cancel it with: oc -n {{os_app}} delete job/job-{{name}}"
- name: Wait for job to complete
shell: oc -n {{os_app}} wait job/job-{{name}} --for condition=complete