-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql-tasks2.yml
87 lines (87 loc) · 2.91 KB
/
mysql-tasks2.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
---
- name: Create data directory for additional mysql instance
become: yes
file:
path: '/var/lib/mysql{{ mysql_instance_id }}'
state: directory
owner: mysql
group: mysql
- name: Create log directory for additional mysql instance
become: yes
file:
path: '/var/log/mysql{{ mysql_instance_id }}'
state: directory
owner: mysql
group: mysql
- name: Prepare writable log files for mysql instance 1/3
become: yes
file:
path: '/var/log/mysql{{ mysql_instance_id }}/error.log'
state: touch
owner: mysql
group: mysql
- name: Prepare writable log files for mysql instance 2/3
become: yes
file:
path: '/var/log/mysql{{ mysql_instance_id }}/mysql-bin.log'
state: touch
owner: mysql
group: mysql
- name: Prepare writable log files for mysql instance 3/3
become: yes
file:
path: '/var/log/mysql{{ mysql_instance_id }}/mysql-relay-bin.log'
state: touch
owner: mysql
group: mysql
- name: Ensure that directory storing socket file of mysql instance exists
become: yes
file:
path: '/var/run/mysqld'
state: directory
owner: mysql
group: mysql
- name: Add AppArmor exceptions for the new instance
become: yes
blockinfile:
path: /etc/apparmor.d/usr.sbin.mysqld
insertbefore: '^}'
block: |
/var/lib/mysql{{ mysql_instance_id }}/ r,
/var/lib/mysql{{ mysql_instance_id }}/** rwk,
/var/run/mysqld/mysqld{{ mysql_instance_id }}.pid rw,
/var/run/mysqld/mysqld{{ mysql_instance_id }}.sock rw,
/var/run/mysqld/mysqld{{ mysql_instance_id }}.sock.lock rw,
/run/mysqld/mysqld{{ mysql_instance_id }}.pid rw,
/run/mysqld/mysqld{{ mysql_instance_id }}.sock rw,
/run/mysqld/mysqld{{ mysql_instance_id }}.sock.lock rw,
/var/log/mysql{{ mysql_instance_id }}/ r,
/var/log/mysql{{ mysql_instance_id }}/** rw,
- name: Restart AppArmor service
become: yes
service:
name: apparmor
state: restarted
- name: Initialize data dir for the new instance
become: yes
ignore_errors: yes
command: 'mysqld --initialize --user=mysql --datadir=/var/lib/mysql{{ mysql_instance_id }}/'
- name: Retrieve temporary password from log file
shell: "grep 'temporary password' /var/log/mysql/error.log | tail -n 1 | awk '{print $NF}'"
register: mysql_tmp_root_pass
- name: Create mysql config file from template
become: yes
template:
src: ./sent_config/mysqld.cnf.j2
dest: /etc/mysql/my{{ mysql_instance_id }}.cnf
owner: mysql
group: mysql
- name: Start mysql instance using mysqld_safe
become: yes
shell: 'nohup mysqld_safe --defaults-file=/etc/mysql/my{{ mysql_instance_id }}.cnf > mysqld_safe-`date -Iseconds`.out &'
- name: Change root password
ignore_errors: yes
shell: >
mysql -uroot -p'{{ mysql_tmp_root_pass.stdout }}' -S /var/run/mysqld/mysqld{{ mysql_instance_id }}.sock \
-e "ALTER USER 'root'@'localhost' IDENTIFIED BY '{{ mysql_root_pass }}';" \
--connect-expired-password