---
- name: stop provisioners
  include: stop_cluster.yaml

# delete the deployment objects that we had created
- name: delete provisioner api objects
  command: >
    {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
    delete {{ item }} --selector provisioners-infra -n {{ openshift_provisioners_project }} --ignore-not-found=true
  with_items:
    - dc
  register: delete_result
  changed_when: delete_result.stdout.find("deleted") != -1 and delete_result.rc == 0

# delete our old secrets
- name: delete provisioner secrets
  command: >
    {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
    delete secret {{ item }} -n {{ openshift_provisioners_project }} --ignore-not-found=true
  with_items:
    - provisioners-efs
  ignore_errors: yes
  register: delete_result
  changed_when: delete_result.stdout.find("deleted") != -1 and delete_result.rc == 0

# delete cluster role bindings
- name: delete cluster role bindings
  command: >
    {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
    delete clusterrolebindings {{ item }} -n {{ openshift_provisioners_project }} --ignore-not-found=true
  with_items:
    - run-provisioners-efs
  register: delete_result
  changed_when: delete_result.stdout.find("deleted") != -1 and delete_result.rc == 0

# delete our service accounts
- name: delete service accounts
  oc_serviceaccount:
    name: "{{ item }}"
    namespace: "{{ openshift_provisioners_project }}"
    state: absent
  with_items:
    - provisioners-efs
