-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql-tasks.yml
34 lines (34 loc) · 957 Bytes
/
mysql-tasks.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
---
- 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: Kill mysql process
become: yes
ignore_errors: yes
shell: "cat /var/run/mysqld/mysqld.pid | xargs kill 2> /dev/null"
- name: Prepare init script
become: yes
shell: "echo \"ALTER USER 'root'@'localhost' IDENTIFIED BY '{{ mysql_root_pass }}';\" > /etc/mysql/root_init.sql"
- name: Rerun mysql server with changed root password
shell: "nohup mysqld --init-script=/etc/mysql/root_init.sql > mysqld-`date -Iseconds`.out &"
- name: Wait
wait_for:
timeout: 2
- name:
become: yes
ignore_errors: yes
shell: "pgrep mysql | xargs kill 2> /dev/null"
- name: Remove init script
become: yes
file:
path: /etc/mysql/root_init.sql
state: absent
- name: Start mysql server
become: yes
service:
name: mysql
state: started