aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lma/ansible-server/roles/clean-logging/tasks/main.yml
blob: 259065ed55fc7b2e273724c84231c3a9818b7e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Copyright 2020 Adarsh yadav
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
#Deleting EFK setup from k8s cluster

#check kubelet is running or not
- name: check for kubelet
  shell: "systemctl status kubelet"
  register: _svc_kubelet
  failed_when: _svc_kubelet.rc != 0 and ("could not be found" not in _svc_kubelet.stderr)

#***********************************************************************************************************
#copy all yaml to /tmp/files/
#***********************************************************************************************************
- name: copy all yaml to /tmp/files/
  copy:
    src: ../../logging/files/
    dest: /tmp/files/

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Stop elastalert
#***********************************************************************************************************
- name: Delete elastalert config configmap
  k8s:
    state: absent
    src: /tmp/files/elastalert/ealert-conf-cm.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

- name: Delete elastalert key configmap
  k8s:
    state: absent
    src: /tmp/files/elastalert/ealert-key-cm.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

- name: Delete elastalert rule configmap
  k8s:
    state: absent
    src: /tmp/files/elastalert/ealert-rule-cm.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

- name: Delete elastalert pod
  k8s:
    state: absent
    src: /tmp/files/elastalert/elastalert.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Stop fluentd
#***********************************************************************************************************

- name: Delete fluentd service
  k8s:
    state: absent
    src: /tmp/files/fluentd/fluent-service.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

- name: Delete fluentd configmap
  k8s:
    state: absent
    src: /tmp/files/fluentd/fluent-cm.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

- name: Delete fluentd pod
  k8s:
    state: absent
    src: /tmp/files/fluentd/fluent.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Stop nginx
#***********************************************************************************************************
- name: Delete nginx service
  k8s:
    state: absent
    src: /tmp/files/nginx/nginx-service.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

- name: Delete nginx configmap
  k8s:
    state: absent
    src: /tmp/files/nginx/nginx-conf-cm.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

- name: Delete nginx key configmap
  k8s:
    state: absent
    src: /tmp/files/nginx/nginx-key-cm.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

- name: Delete nginx pod
  k8s:
    state: absent
    src: /tmp/files/nginx/nginx.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Stop Kibana
#***********************************************************************************************************
- name: Stopping Kibana
  k8s:
    state: absent
    src: /tmp/files/kibana/kibana.yaml
    namespace: logging
  ignore_errors: yes
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Stop Elasticsearch
#***********************************************************************************************************
- name: Stopping Elasticsearch
  k8s:
    state: absent
    src: /tmp/files/elasticsearch/elasticsearch.yaml
    namespace: logging
  ignore_errors: yes
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Stop Elasticsearch operator
#***********************************************************************************************************
- name: Stopping Elasticsearch operator
  shell: kubectl delete -f https://download.elastic.co/downloads/eck/1.2.0/all-in-one.yaml
  ignore_errors: yes
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Delete Persistent Volume
#***********************************************************************************************************
- name: Deleting Persistent Volume
  k8s:
    state: absent
    src: /tmp/files/persistentVolume.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Delete Storage Class
#***********************************************************************************************************
- name: Deleting Storage Class
  k8s:
    state: absent
    src: /tmp/files/storageClass.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#IF KUBELET IS RUNNING, THEN
#Delete Namespace
#***********************************************************************************************************
- name: Deleting Namespace
  k8s:
    state: absent
    src: /tmp/files/namespace.yaml
    namespace: logging
  when: "_svc_kubelet.rc == 0"

#***********************************************************************************************************
#removing /tmp/files
#***********************************************************************************************************
- name: Removing /tmp/files
  file:
    path: "/tmp/files"
    state: absent