-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.yaml
281 lines (263 loc) · 8.49 KB
/
database.yaml
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
---
- hosts: db,frontend_db,backend_db,cluster_control
gather_facts: true
tags: facts
- hosts: db,frontend_db,backend_db,cluster_control
gather_facts: false
vars_files:
- settings.yaml
roles:
- lasair_instance
tags: lasair_instance
- hosts: db,frontend_db,backend_db
gather_facts: false
become: yes
tasks:
- name: create filesystem for data
community.general.filesystem:
fstype: ext4
dev: /dev/sdb
- name: ensure data filesystem is mounted
ansible.posix.mount:
path: /var/lib/mysql
src: /dev/sdb
fstype: ext4
opts: nofail
state: mounted
tags: filesystem
- hosts: db
gather_facts: false
roles:
- gkansible.gkservercollection.mariadb
vars_files:
- settings.yaml
vars:
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
mysql_root_password: "{{ settings.master_db_root_password }}"
datadir: /var/lib/mysql
tags: standalone
- hosts: cluster_control,frontend_db,backend_db
roles:
- gkansible.gkservercollection.basic_packages
vars_files:
- settings.yaml
vars:
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
tags: basic_packages
- hosts: cluster_control
gather_facts: false
become: yes
tasks:
- name: "Install python3-mysqldb"
become: true
apt:
pkg: python3-mysqldb
state: present
update-cache: yes
tags: cluster_control
- hosts: cluster_control
gather_facts: false
become: yes
roles:
- gkansible.gkservercollection.severalnines_clustercontrol
vars_files:
- settings.yaml
vars:
runtag: "controller"
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
mysql_root_password: "{{ settings.master_db_root_password }}"
cmon_mysql_password: "{{ settings.master_db_root_password }}"
cc_admin:
- set: true
email: "{{ admin_email }}"
password: "{{ settings.master_db_root_password }}"
cc_license:
- set: false
tags: cluster_control_1
- hosts: backend_db,frontend_db
gather_facts: false
become: yes
roles:
- role: gkansible.gkservercollection.severalnines_clustercontrol
tags: dbnodes
vars:
runtag: "dbnodes"
clustercontrol_ip_address: "{{ hostvars[groups['cluster_control'][0]]['ansible_all_ipv4_addresses'][0] }}"
remote_login_user: "root"
remote_login_user_home: "/root"
ssh_keyfile: "{{ remote_login_user_home }}/.ssh/id_rsa"
ssh_user: "{{ remote_login_user }}"
tags: db_1
- hosts: cluster_control
gather_facts: false
become: yes
roles:
- role: gkansible.gkservercollection.severalnines_clustercontrol
tags: "deploy-database"
vars_files:
- settings.yaml
vars:
runtag: "deploy-database"
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
mysql_root_password: "{{ settings.master_db_root_password }}"
remote_login_user: "root"
remote_login_user_home: "/root"
clustercontrol_ip_address: "{{ hostvars[groups['cluster_control'][0]]['ansible_all_ipv4_addresses'][0] }}"
cc_cluster:
# minimal create new galera
- deployment: true
operation: "create"
cluster_type: "galera"
cluster_name: "galera_cluster"
mysql_cnf_template: "my.cnf.mdb10x-galera"
mysql_datadir: "/var/lib/mysql"
mysql_root_password: "{{ settings.master_db_root_password }}"
mysql_hostnames: "{{ groups['backend_db'] + groups['frontend_db'] }}"
mysql_password: "{{ settings.master_db_root_password }}"
cmon_mysql_password: "{{ settings.master_db_root_password }}"
mysql_port: 3306
mysql_version: "10.6"
ssh_keyfile: "{{ remote_login_user_home }}/.ssh/id_rsa"
ssh_user: "{{ remote_login_user }}"
sudo_password: ""
vendor: "mariadb"
nodes: |
[
{%- for host in groups['backend_db'] + groups['frontend_db'] -%}
{ "hostname": "{{ host }}", "hostname_data": "{{ host }}", "hostname_internal": "", "port": "3306" },
{%- endfor -%}
]
tags: cluster_control_2
- hosts: db,cluster_control,backend_db,frontend_db
gather_facts: false
tasks:
- name: Wait for port 3306 to become open on database hosts
wait_for:
port: 3306
timeout: 3600
- name: Wait for another 60s to make sure everything is done
wait_for:
timeout: 60
tags: wait
# Work in progress - stepping over this one play at a time appears to work
# but running the whole playbook is failing - probably not waiting long enough/for the right thing
- hosts: backend_db,frontend_db
gather_facts: false
become: true
roles:
- gkansible.gkservercollection.severalnines_clustercontrol
vars_files:
- settings.yaml
vars:
runtag: "credential-templates"
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
mysql_root_username: root
mysql_root_password: "{{ settings.master_db_root_password }}"
tags: db_2
# Setup Maxscale - this can only run once the databases are up and running
- hosts: frontend_db
gather_facts: false
become: true
become_user: root
vars_files:
- settings.yaml
vars:
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
password: "{{ settings.maxscale_password }}"
ip: "{{ hostvars[groups['cluster_control'][0]]['ansible_all_ipv4_addresses'][0] }}"
tasks:
- name: Install PyMySQL
apt:
pkg: python3-pymysql
state: present
update-cache: yes
- name: Add MaxScale MySQL User on Cluster
community.mysql.mysql_query:
query:
- CREATE USER IF NOT EXISTS 'maxscale'@'{{ ip }}' IDENTIFIED BY "{{ password }}"
- GRANT SELECT ON mysql.user TO 'maxscale'@'{{ ip }}';
- GRANT SELECT ON mysql.db TO 'maxscale'@'{{ ip }}';
- GRANT SELECT ON mysql.tables_priv TO 'maxscale'@'{{ ip }}';
- GRANT SELECT ON mysql.columns_priv TO 'maxscale'@'{{ ip }}';
- GRANT SELECT ON mysql.proxies_priv TO 'maxscale'@'{{ ip }}';
- GRANT SELECT ON mysql.roles_mapping TO 'maxscale'@'{{ ip }}';
- GRANT SHOW DATABASES ON *.* TO 'maxscale'@'{{ ip }}';
login_user: root
login_password: "{{ password }}"
single_transaction: yes
register: result
until: result is success
retries: 90
delay: 10
tags: maxscale_user
- hosts: backend_db,frontend_db
gather_facts: false
become: true
tasks:
- name: Request lowercase tables names on all mysql servers
ini_file:
path: /etc/mysql/my.cnf
section: MYSQLD
option: lower_case_table_names
value: "1"
backup: no
- name: Request lowercase tables names on all mysql servers
ini_file:
path: /etc/mysql/my.cnf
section: MYSQLD
option: log_bin_trust_function_creators
value: "1"
backup: no
- name: Increase open file limit
ini_file:
path: /etc/systemd/system/mariadb.service.d/override.conf
section: Service
option: LimitNOFILE
value: "infinity"
backup: no
tags: lc_tables
- hosts: cluster_control
gather_facts: false
become: true
vars_files:
- settings.yaml
vars:
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
maxscale_deb_url: https://dlm.mariadb.com/1961572/MaxScale/2.5.18/packages/ubuntu/focal/x86_64/maxscale-2.5.18-1.ubuntu.focal.x86_64.deb
backend_servers: "{{ groups['backend_db'] }}"
frontend_servers: "{{ groups['frontend_db'] }}"
roles:
- gkansible.gkservercollection.maxscale
tags: maxscale
- hosts: cluster_control
gather_facts: false
become: true
vars_files:
- settings.yaml
vars:
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
runtag: "credential-templates"
backend_servers: "{{ groups['backend_db'] }}"
frontend_servers: "{{ groups['frontend_db'] }}"
roles:
- gkansible.gkservercollection.maxscale
tags: maxscale
- hosts: cluster_control
gather_facts: false
become: true
tasks:
- name: maxscale restart
service:
name: maxscale
state: restarted
tags: maxscale
- hosts: db,backend_db[0]
gather_facts: false
vars_files:
- settings.yaml
vars:
settings: "{{ lookup('hashi_vault', 'secret='+vault.path+'/settings url='+vault.url)}}"
git_branch: "{{ lasair_version }}"
roles:
- lasair_database
tags: setup_database