-
Notifications
You must be signed in to change notification settings - Fork 266
/
infra-rm.yml
executable file
·135 lines (120 loc) · 4.05 KB
/
infra-rm.yml
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
#!/usr/bin/env ansible-playbook
---
#==============================================================#
# File : infra-rm.yml
# Desc : uninstall pigsty infra module
# Ctime : 2022-02-22
# Mtime : 2024-11-15
# Path : infra-rm.yml
# License : AGPLv3 @ https://pigsty.io/docs/about/license
# Copyright : 2018-2024 Ruohang Feng / Vonng ([email protected])
#==============================================================#
#---------------------------------------------------------------
# Usage
#---------------------------------------------------------------
# ./infra-rm.yml # remove everything about infra
# ./infra-rm.yml -t service # stop infra services
# ./infra-rm.yml -t data # remove infra data
# ./infra-rm.yml -t package # uninstall infra packages
#---------------------------------------------------------------
#--------------------------------------------------------------#
# Remove Infrastructure
#--------------------------------------------------------------#
- name: INFRA REMOVE
become: yes
hosts: infra
gather_facts: no
ignore_errors: yes
tasks:
#---------------------------------------------
# Stop Service
#---------------------------------------------
- name: stop infra service
systemd: name={{ item }} state=stopped enabled=no daemon_reload=yes
tags: service
with_items:
- alertmanager
- pushgateway
- blackbox_exporter
- prometheus
- loki
- grafana-server
- nginx_exporter
- nginx
- dnsmasq
#---------------------------------------------
# Remove conf
#---------------------------------------------
- name: remove infra conf
file: state=absent path="{{ item }}"
tags: config
vars: { systemd_dir: "{% if os_package is defined and os_package == 'deb' %}/lib/systemd/system/{% else %}/usr/lib/systemd/system{% endif %}" }
with_items:
- /etc/pigsty
- /etc/pki/infra.crt
- /etc/pki/infra.key
- /etc/alertmanager.yml
- /etc/default/alertmanager
- "{{ systemd_dir }}/alertmanager.service"
- /etc/blackbox.conf
- /etc/default/blackbox_exporter
- "{{ systemd_dir }}/blackbox_exporter.service"
- /etc/default/pushgateway
- "{{ systemd_dir }}/pushgateway.service"
- /etc/prometheus
- /etc/default/prometheus
- "{{ systemd_dir }}/prometheus.service"
- /etc/loki.yml
- "{{ systemd_dir }}/loki.service"
- /etc/grafana
- "{{ systemd_dir }}/grafana.service"
- /etc/nginx/
- /etc/default/nginx_exporter
- "{{ systemd_dir }}/nginx.service"
- "{{ systemd_dir }}/nginx_exporter.service"
- /etc/dnsmasq.conf
- "{{ systemd_dir }}/dnsmasq.service"
#---------------------------------------------
# Remove Env
#---------------------------------------------
- name: remove infra env
become: no
file: state=absent path="{{ item }}"
tags: env
with_items:
- '~/.pg_service.conf'
- '~/.servers.json'
- '~/.pgpass'
- '~/.pigsty'
- '~/.pgpass'
#---------------------------------------------
# Remove Infra Data
#---------------------------------------------
- name: remove infra data
file: state=absent path="{{ item }}"
tags: data
with_items:
- "{{ prometheus_data|default('/data/prometheus') }}"
- "{{ loki_data|default('/data/loki') }}"
- "{{ nginx_home|default('/www') }}"
- /var/lib/grafana
- /etc/hosts.d
#---------------------------------------------
# Uninstall Packages
#---------------------------------------------
- name: uninstall infra packages
package: name={{ item }} state=removed
tags: package
with_items:
- alertmanager
- pushgateway
- blackbox_exporter
- prometheus2
- loki
- grafana
- nginx_exporter
- nginx
- dnsmasq
- mcli
- logcli
...