uninstall_prometheus.yaml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ---
  2. - name: Remove node_exporter daemon set
  3. oc_obj:
  4. state: absent
  5. name: "prometheus-node-exporter"
  6. namespace: "{{ openshift_prometheus_namespace }}"
  7. kind: daemonset
  8. - name: Remove node_exporter services
  9. oc_service:
  10. state: absent
  11. name: "prometheus-node-exporter"
  12. namespace: "{{ openshift_prometheus_namespace }}"
  13. - name: Remove prometheus stateful set
  14. oc_obj:
  15. state: absent
  16. name: "prometheus"
  17. namespace: "{{ openshift_prometheus_namespace }}"
  18. kind: statefulset
  19. - name: Remove prometheus configmaps
  20. oc_configmap:
  21. state: absent
  22. name: "{{ item }}"
  23. namespace: "{{ openshift_prometheus_namespace }}"
  24. with_items:
  25. - "prometheus"
  26. - "alertmanager"
  27. - name: Remove prometheus PVCs
  28. oc_pvc:
  29. namespace: "{{ openshift_prometheus_namespace }}"
  30. name: "{{ item }}"
  31. state: absent
  32. with_items:
  33. - "{{ openshift_prometheus_pvc_name }}"
  34. - "{{ openshift_prometheus_alertmanager_pvc_name }}"
  35. - "{{ openshift_prometheus_alertbuffer_pvc_name }}"
  36. - name: Remove prometheus and alerts routes
  37. oc_route:
  38. state: absent
  39. name: "{{ item.name }}"
  40. namespace: "{{ openshift_prometheus_namespace }}"
  41. with_items:
  42. - name: prometheus
  43. - name: alerts
  44. - name: alertmanager
  45. - name: Remove services for prometheus
  46. oc_service:
  47. state: absent
  48. name: "{{ item }}"
  49. namespace: "{{ openshift_prometheus_namespace }}"
  50. with_items:
  51. - "{{ openshift_prometheus_service_name }}"
  52. - "{{ openshift_prometheus_alertmanager_service_name }}"
  53. - "{{ openshift_prometheus_alerts_service_name }}"
  54. - name: Remove prometheus secrets
  55. oc_secret:
  56. state: absent
  57. name: "{{ item }}-proxy"
  58. namespace: "{{ openshift_prometheus_namespace }}"
  59. with_items:
  60. - prometheus
  61. - alerts
  62. - alertmanager
  63. - name: Remove prometheus serviceaccounts
  64. oc_serviceaccount:
  65. state: absent
  66. name: "{{ item }}"
  67. namespace: "{{ openshift_prometheus_namespace }}"
  68. with_items:
  69. - "{{ openshift_prometheus_service_name }}"
  70. - "{{ openshift_prometheus_reader_serviceaccount_name }}"
  71. - prometheus-node-exporter
  72. # Check for any remaining objects in the namespace
  73. - name: Get all objects in prometheus namespace
  74. oc_obj:
  75. state: list
  76. kind: all
  77. namespace: "{{ openshift_prometheus_namespace }}"
  78. register: __prometheus_namespace_objects
  79. - name: Set prometheus objects facts
  80. set_fact:
  81. num_prometheus_objects: "{{ __prometheus_namespace_objects['results']['results'][0]['items'] | length }}"
  82. # If there are no remaining objects then it should be safe to delete
  83. # the clusterrole and the project/namespace
  84. - name: delete router-metrics cluster role
  85. oc_obj:
  86. state: absent
  87. kind: clusterrole
  88. name: router-metrics
  89. when: num_prometheus_objects | int == 0
  90. - name: Remove prometheus project
  91. oc_project:
  92. state: absent
  93. name: "{{ openshift_prometheus_namespace }}"
  94. when: num_prometheus_objects | int == 0