---
- name: list installed jobs
  command: >
    {{ openshift_client_binary }} -n {{ openshift_metrics_project }} --config={{ mktemp.stdout }}/admin.kubeconfig
    get jobs
  register: jobs

# We cannot use oc apply here because the Job template has immutable fields
# on which oc apply will fail.
- name: remove hawkular-metrics-schema job
  command: >
    {{ openshift_client_binary }} -n {{ openshift_metrics_project }} --config={{ mktemp.stdout }}/admin.kubeconfig
    delete job hawkular-metrics-schema
  register: delete_schema_job
  when: "'hawkular-metrics-schema' in jobs.stdout"

- name: generate hawkular-metrics schema job
  template:
    src: hawkular_metrics_schema_job.j2
    dest: "{{ mktemp.stdout }}/templates/hawkular_metrics_schema_job.yaml"
  changed_when: false
