-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpercona.yml
189 lines (168 loc) · 5.17 KB
/
percona.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
---
- hosts: all
become: true
become_user: root
remote_user: vagrant
gather_facts: true
vars_files:
- vars.yml
pre_tasks:
- name: Update apt repo and cache on Ubuntu box
apt:
update_cache: yes
force_apt_get: yes
cache_valid_time: 3600
- name: Upgrade all packages on servers
apt:
upgrade: dist
force_apt_get: yes
- name: Install required packages
apt:
name:
- wget
- python3-psycopg2
- acl
state: latest
- name: Install repo and deb files for percona
become: yes
block:
- name: Download percona repo
get_url:
url: "https://repo.percona.com/apt/percona-release_latest.generic_all.deb"
dest: /home/vagrant
when: ansible_os_family == "Debian"
- name: Install percona repo
apt:
deb: /home/vagrant/percona-release_latest.generic_all.deb
when: ansible_os_family == "Debian"
- name: Update and upgrade apt packages for percona
apt:
update_cache: yes
when: ansible_os_family == "Debian"
- name: Select Percona release
shell: |
export DEBIAN_FRONTEND=noninteractive &&
percona-release enable-only pxc-80 release &&
percona-release enable tools release
- name: Install Percona Percona XtraDB Cluster
apt:
update_cache: yes
force_apt_get: yes
cache_valid_time: 3600
name:
- percona-xtradb-cluster
- percona-xtradb-cluster-client
- percona-xtradb-cluster-server
state: present
- name: Copy shared CA KEY file
ansible.builtin.copy:
src: ca-key.pem
dest: /var/lib/mysql/
owner: mysql
group: mysql
mode: '0600'
- name: Copy shared CA PEM file
ansible.builtin.copy:
src: ca.pem
dest: /var/lib/mysql/
owner: mysql
group: mysql
mode: '0644'
- name: Copy shared Client CERT file
ansible.builtin.copy:
src: client-cert.pem
dest: /var/lib/mysql/
owner: mysql
group: mysql
mode: '0644'
- name: Copy shared Client KEY file
ansible.builtin.copy:
src: client-key.pem
dest: /var/lib/mysql/
owner: mysql
group: mysql
mode: '0600'
- name: Copy shared(all nodes) private KEY file
ansible.builtin.copy:
src: private_key.pem
dest: /var/lib/mysql/
owner: mysql
group: mysql
mode: '0600'
- name: Copy shared(all nodes) public KEY file
ansible.builtin.copy:
src: public_key.pem
dest: /var/lib/mysql/
owner: mysql
group: mysql
mode: '0644'
- name: Copy shared(all nodes) server CERT file
ansible.builtin.copy:
src: server-cert.pem
dest: /var/lib/mysql/
owner: mysql
group: mysql
mode: '0644'
- name: Copy shared(all nodes) server KEY file
ansible.builtin.copy:
src: server-key.pem
dest: /var/lib/mysql/
owner: mysql
group: mysql
mode: '0600'
- name: Bootstrap | ensure bootstrap service is started on first DB node
shell: systemctl start [email protected]
async: 300
poll: 5
when: inventory_hostname == 'db1'
register: result
- name: "Start and enable services"
service: "name={{ item }} state=started enabled=yes"
with_items:
- mysql
when: inventory_hostname !== 'db1' AND result.stat.isreg IS DEFINED AND result.stat.isreg
- name: Configure percona cluster mysqld.conf
tags: [ percona ]
template:
src=./roles/templates/percona/mysqld.conf.j2
dest=/etc/mysql/mysql.conf.d/mysqld.cnf
owner: root
group: root
mode: '644'
- name: Set percona config variable
lineinfile:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
regexp: '^wsrep_cluster_address'
line: 'wsrep_cluster_address=gcomm://192.168.88.11,192.168.88.12,192.168.88.13'
backup: yes
- name: Set percona config variable
lineinfile:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
regexp: '^wsrep_node_address'
line: 'wsrep_node_address=192.168.88.11'
backup: yes
# pxc_encrypt_cluster_traffic=ON
# 26 wsrep_provider_options="socket.ssl_key=server-key.pem;socket.ssl_cert=server-cert.pem;socket.ssl_ca=ca.pem"
# wsrep_cluster_conf_id=
handlers:
- name: Restart Percona mysql
service: name=mysql state=restarted
- name: Verify
hosts: all
tasks:
- name: Make sure we can connect to MySQL via Unix socket.
command: "mysql -u root -e 'show databases;'"
become: true
changed_when: false
- name: Testing for TCP port 3306 to become open on the host, don't start checking for 2 seconds
ansible.builtin.wait_for:
port: 3306
delay: 2
- name: Show server status
block:
- command: "mysql -u root -NBe 'status'"
become: true
changed_when: false
register: mysql_status
- debug:
var: mysql_status.stdout