forked from percona/pmm-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
playbook-install.yml
243 lines (207 loc) · 7.93 KB
/
playbook-install.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
---
- hosts: all
become: yes
gather_facts: yes
tasks:
- name: Packages | Add Percona repository
when: ansible_os_family == 'RedHat'
yum:
name: https://www.percona.com/redir/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
state: installed
- name: Packages | Update OS
when: ansible_os_family == 'RedHat'
yum:
name: '*'
state: latest
exclude: 'ansible'
disablerepo: percona-release-x86_64
- name: Packages | Install OS tools
when: ansible_os_family == 'RedHat'
yum: name={{ item }} state=installed
with_items:
- screen
- yum-utils
- yum-cron
- supervisor
- logrotate
- name: cloud-init | Create dirs
file: path={{ item }} state=directory
with_items:
- /var/lib/cloud/scripts/per-once
- /var/lib/cloud/scripts/per-boot
- name: cloud-init | Create dirs
file: path={{ item }} state=directory owner=pmm
with_items:
- /opt/prometheus/data
- /opt/consul-data
- name: cloud-init | Configure yum-cron
replace:
dest: /etc/yum/yum-cron-hourly.conf
regexp: 'update_cmd = default'
replace: 'update_cmd = minimal-security'
- name: cloud-init | Configure yum-cron
replace:
dest: /etc/yum/yum-cron.conf
regexp: 'update_cmd = default'
replace: 'update_cmd = minimal-security'
- name: Percona Server for MySQL | Install Percona Client
when: ansible_os_family == 'RedHat'
yum: name={{ item }} state=installed
with_items:
- Percona-Server-client-55
- name: Percona Server for MySQL | Remove MariaDB Client
when: ansible_os_family == 'RedHat'
yum: name={{ item }} state=absent
with_items:
- mariadb-libs
- name: Percona Server for MySQL | Install Percona Server
when: ansible_os_family == 'RedHat'
yum: name={{ item }} state=installed
with_items:
- Percona-Server-server-55
- MySQL-python
- name: Percona Server for MySQL | stat /root/.my.cnf
stat: path=/root/.my.cnf
register: root_mycnf_file
- name: Percona Server for MySQL | Add password generator script
when: not root_mycnf_file.stat.exists
copy:
content: |
#!/bin/sh
TEMP_PASS=$(grep 'temporary password' /var/log/mysqld.log | sed -e 's/.*localhost: //' | tail -1)
NEW_PASS=$(dd if=/dev/urandom bs=1 count=256 2>/dev/null | tr -cd '[:alnum:],.!@#$%^&*' | head -c32)
mysql "-p${TEMP_PASS}" --connect-expired-password -e "SET PASSWORD = PASSWORD('$NEW_PASS');"
echo "[client]
password = '$NEW_PASS'" > /root/.my.cnf
echo "
++++++++++++++++++++++++++ Percona Server for MySQL ++++++++++++++++++++++++++
Setting password for root@localhost user: $NEW_PASS
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
" | tee -a /var/log/mysqld.log
dest: /var/lib/cloud/scripts/per-once/init-mysql-password
mode: 0755
- name: PMM | Create grafana group
group:
gid: 996
name: grafana
- name: PMM | Create grafana user
user:
uid: 996
name: grafana
group: grafana
home: /etc/grafana
shell: /sbin/nologin
- name: PMM | Add PMM Server YUM repository
when: ansible_os_family == 'RedHat'
yum_repository:
name: pmm
description: PMM Server YUM repository - x86_64
baseurl: https://repo.percona.com/pmm/7/RPMS/x86_64/
gpgcheck: yes
enabled: no
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Percona
- name: PMM | Add PMM Server YUM repository
when: ansible_os_family == 'RedHat'
yum_repository:
name: pmm-laboratory
description: PMM Server YUM repository - x86_64
baseurl: https://repo.percona.com/laboratory/7/RPMS/x86_64/
gpgcheck: yes
enabled: no
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Percona
- name: PMM | Install RPMs
when: ansible_os_family == 'RedHat'
yum: name={{ item }} state=installed enablerepo=pmm-laboratory
with_items:
- nginx
- percona-consul
- percona-grafana
- percona-prometheus
- percona-orchestrator
- percona-qan-api
- percona-qan-app
- percona-toolkit
- percona-dashboards
- pmm-server
- pmm-client
- pmm-manage
- pmm-managed
- pmm-update
- rds_exporter
- name: PMM | Fix nginx config
replace:
dest: /etc/nginx/nginx.conf
regexp: '^(\s*)listen'
replace: '\1#listen'
- name: NGINX SSL Certificate | Add script
copy:
content: |
#!/bin/sh
set -o errexit
mkdir -p /srv/nginx
if [ ! -e /srv/nginx/dhparam.pem ]; then
openssl dhparam -out /srv/nginx/dhparam.pem 2048
fi
if [ ! -e /srv/nginx/ca-certs.pem ]; then
# Fetch letsencrypt chain
curl https://letsencrypt.org/certs/isrgrootx1.pem > /srv/nginx/ca-certs.pem
curl https://letsencrypt.org/certs/lets-encrypt-x1-cross-signed.pem >> /srv/nginx/ca-certs.pem
curl https://letsencrypt.org/certs/letsencryptauthorityx1.pem >> /srv/nginx/ca-certs.pem
curl https://www.identrust.com/certificates/trustid/root-download-x3.html >> /srv/nginx/ca-certs.pem
fi
if [ ! -e /srv/nginx/certificate.conf ]; then
echo "
[ req ]
distinguished_name = req_distinguished_name
prompt = no
[ req_distinguished_name ]
O = Main Org.
" > /srv/nginx/certificate.conf
fi
if [ ! -e /srv/nginx/certificate.key -o ! -e /srv/nginx/certificate.crt ]; then
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /srv/nginx/certificate.key \
-out /srv/nginx/certificate.crt \
-config /srv/nginx/certificate.conf
fi
dest: /var/lib/cloud/scripts/per-boot/generate-ssl-certificate
mode: 0755
- name: NGINX SSL Certificate | Check certificate file
stat: path=/srv/nginx/certificate.crt
register: certificate_file
- name: NGINX SSL Certificate | Generate certificate
when: not certificate_file.stat.exists
command: /var/lib/cloud/scripts/per-boot/generate-ssl-certificate
- name: Grafana | Check data dir
stat: path=/srv/grafana/grafana.db
register: grafana_db
- name: Grafana | Enable Anonymous access
when: not grafana_db.stat.exists
ini_file:
dest: /etc/grafana/grafana.ini
section: auth.anonymous
option: enabled
value: true
- name: Grafana | Enable Anonymous access
when: not grafana_db.stat.exists
ini_file:
dest: /etc/grafana/grafana.ini
section: auth.anonymous
option: org_role
value: Editor
- name: supervisor | Fix credentials
ini_file:
dest: /etc/supervisord.conf
section: supervisorctl
option: username
value: dummy
- name: supervisor | Fix credentials
ini_file:
dest: /etc/supervisord.conf
section: supervisorctl
option: password
value: dummy
- name: MySQL | Add includedir to MySQL config
lineinfile:
dest: /etc/my.cnf
line: '!includedir /etc/my.cnf.d/'