-
Notifications
You must be signed in to change notification settings - Fork 2
/
hosts.yml
316 lines (271 loc) · 8.45 KB
/
hosts.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#
# This playbook manages all "machine types" for Percona Training
#
- hosts: all
roles:
- common
- hosts: node1
gather_facts: no
roles:
- minikube
# This should only match "db1" hosts
- hosts: db1
gather_facts: no
roles:
- mysql
- sysbench
tasks:
- name: Install Percona Repo
yum:
state: latest
name:
- http://repo.percona.com/yum/percona-release-latest.noarch.rpm
- name: install PMM2 client, mydumper, etc
yum:
state: installed
disable_gpg_check: yes
name:
- pmm2-client
- https://github.com/mydumper/mydumper/releases/download/v0.12.5-3/mydumper-0.12.5-3.el7.x86_64.rpm
- httpd
- php
- php-mysql
- mysql-utilities
- openssl
- nc
- name: clone my-movies repo
git:
repo: https://github.com/percona/training-mymovies
dest: /var/www/html
update: no
- name: start httpd
service: name=httpd state=started
# - name: Download zip codes
# unarchive:
# src: https://simplemaps.com/static/data/us-zips/1.5/basic/simplemaps_uszips_basicv1.5.zip
# dest: /home/centos/
# remote_src: yes
# This should only match "db2" hosts to remove everything in
# preparation for setting up a slave
- hosts: db2
gather_facts: no
roles:
- mysql
tasks:
- name: check for existing setup
stat: path=/var/lib/mysql/xtrabackup_binlog_info
register: existing_setup
- name: disable mysql
service: name=mysql state=stopped
ignore_errors: yes
when: not existing_setup.stat.exists
- name: remove percona packages
yum:
state: removed
name:
- 'percona-server-*'
- 'percona-*'
- pmm-client
- pmm2-client
when: not existing_setup.stat.exists
- name: move back my.cnf
copy: remote_src=True src=/etc/my.cnf.rpmsave dest=/etc/my.cnf
# Setup the scoreboard for my-movies
- hosts: scoreboard
gather_facts: no
roles:
- scoreboard
# Setup PXC/GR "app" node with sysbench, scripts, proxysql, and mysqlrouter
- hosts: app
gather_facts: no
roles:
- sysbench
tasks:
- name: Install Percona Repo
yum:
state: latest
name:
- http://repo.percona.com/yum/percona-release-latest.noarch.rpm
- name: Install Percona client, libs, proxysql2, router, shell, pmm2-client
yum:
state: latest
name:
- percona-server-client
- percona-server-shared
- percona-mysql-router
- percona-mysql-shell
- pmm2-client
- proxysql2
- name: Remove Percona Server
yum:
state: absent
name: percona-server-server
- name: Remove my.cnf
ansible.builtin.file:
path: /etc/my.cnf
state: absent
## Settings for PXC/GR tutorial
- hosts: mysql1:mysql2:mysql3
gather_facts: no
roles:
- mysql
tasks:
- name: Fetch latest PXC version
tags: fetchver
shell: >
curl -s https://raw.githubusercontent.com/percona/percona-docker/main/percona-xtradb-cluster-8.0/Dockerfile |
grep "ENV PXC_VERSION" | cut -d " " -f 3 | cut -d "-" -f 1
register: pxcversion
run_once: true
- name: Install Percona Repo
yum:
state: latest
name:
- http://repo.percona.com/yum/percona-release-latest.noarch.rpm
- name: Version lock PS {{ pslock | default(pxcversion.stdout) }}
shell: >
yum versionlock clear &&
yum versionlock percona-server-*-{{ pslock | default(pxcversion.stdout) }} percona-xtradb-cluster-*-{{ pslock | default(pxcversion.stdout) }}
- name: Enable Percona Toolkit Repo
shell: >
percona-release enable pt
- name: Install Percona Server/Client
yum:
state: latest
name:
- percona-server-server
- percona-server-client
- percona-toolkit
- perl-DBD-MySQL
- pmm2-client
- percona-xtrabackup-80
- name: Update mysqld /etc/my.cnf Parameters
tags: update_mycnf
register: mysqldconfig
ini_file:
path: /etc/my.cnf
section: "{{ item.section }}"
option: "{{ item.param }}"
value: "{{ item.value }}"
state: "{{ item.state }}"
with_items:
- { section: "mysqld", param: "server_id", value: "{{ 101 |random(start=2, seed=inventory_hostname) }}", state: "present" }
- { section: "mysqld", param: "keyring_file_data", value: "/var/lib/mysql-keyring/keyring", state: "present" }
- { section: "mysql", param: "prompt", value: "\"{{inventory_hostname}} mysql> \"", state: "present" }
- name: Restart mysql
tags: update_mycnf
service: name=mysql state=restarted enabled=yes
when: (mysqldconfig is changed)
# For PXC/GR tutorial, on mysql1, create replication user to set up initial labs
- hosts: mysql1
gather_facts: no
roles:
- sysbench
tasks:
- name: Create repl user
shell: >
mysql -uroot -e "CREATE USER IF NOT EXISTS 'repl'@'10.%' IDENTIFIED BY 'R3plica1234#';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repl'@'10.%';"
- name: Copy proxysql GR views
copy:
src: roles/gr/files/proxysql_gr.sql
dest: /home/centos/proxysql_gr.sql
- name: mysqltmp 1gb file, loop, mount
shell: >
dd if=/dev/zero of=/slowtmp.disk bs=1024k count=2048 2>&1 >/dev/null; \
loop=$(losetup --show --find /slowtmp.disk); \
size=$(blockdev --getsz $loop); \
echo "0 $size delay $loop 0 500" | dmsetup create dm-slow; \
chmod 777 /dev/mapper/dm-slow && mkfs.xfs /dev/mapper/dm-slow 2>&1 >/dev/null; \
mount /dev/mapper/dm-slow /mnt/ && mkdir /mnt/mysqltmp && chown mysql:mysql /mnt/mysqltmp
when: pmmtutorial is defined and pmmtutorial == "Y"
- name: Update my.cnf for pmm tutorial
register: mysqldconfig
ini_file:
path: /etc/my.cnf
section: "{{ item.section }}"
option: "{{ item.param }}"
value: "{{ item.value }}"
state: "{{ item.state }}"
with_items:
- { section: "mysqld", param: "innodb_buffer_pool_size", value: "128M", state: "present" }
when: pmmtutorial is defined and pmmtutorial == "Y"
- name: Restart mysql
service: name=mysql state=restarted enabled=yes
when: (mysqldconfig is changed)
# For PXC/GR tutorial, connect replication
- hosts: mysql2:mysql3
gather_facts: no
roles:
- mysql
tasks:
- name: Connect Async Replication
tags: connect_replication
shell: >
mysql -uroot -e "STOP SLAVE; RESET SLAVE ALL;
CHANGE MASTER TO MASTER_HOST='{{ hostvars[inventory_hostname]['mysql_master_host'] }}',
MASTER_USER='repl', MASTER_PASSWORD='R3plica1234#',
MASTER_LOG_FILE='mysqld-bin.000001', MASTER_LOG_POS=4, MASTER_SSL=1; START SLAVE;"
- name: GROUP REPLICATION - Drop everything, reset master, purge binlogs
shell: >
mysql -uroot -e "STOP SLAVE; RESET SLAVE ALL;
DROP DATABASE IF EXISTS imdb;
DROP DATABASE IF EXISTS world;
DROP DATABASE IF EXISTS sakila;
DROP DATABASE IF EXISTS sysbench;
FLUSH BINARY LOGS;
RESET MASTER;"
when: gr is defined and gr == "Y" and 'mysql3' in inventory_hostname
# For MongoDB exercises
- hosts: mongodb
gather_facts: no
environment:
PERCONA_TELEMETRY_DISABLE: 1
tasks:
- name: Ensure basic packages installed
yum: pkg={{ item }} state=installed
with_items:
- perl
- ruby
- name: install Percona key
rpm_key:
key: https://repo.percona.com/yum/PERCONA-PACKAGING-KEY
state: present
- name: install Percona repositories
package:
name: https://repo.percona.com/yum/percona-release-latest.noarch.rpm
state: present
- name: Enable the specific MongoDB version
shell: "/usr/bin/percona-release enable psmdb-60 && /usr/bin/percona-release enable tools"
- name: install RPM from repository
package:
name: "{{ item }}"
state: present
with_items:
- percona-server-mongodb
- percona-backup-mongodb
- pmm2-client
- name: disable telemetry
systemd:
name: percona-telemetry-agent
enabled: false
state: stopped
daemon_reload: yes
ignore_errors: true
- name: Create a symbolic link for Mongo shell
become: yes
ansible.builtin.file:
src: /bin/mongosh
dest: /bin/mongo
owner: root
group: root
state: link
- name: Stop default MongoDB instance
service:
name: mongod
state: stopped
enabled: false
- name: Delete default MongoDB directory
file:
path: "/var/lib/mongo/"
state: absent