-
Notifications
You must be signed in to change notification settings - Fork 2
/
mysql_upgrade.yml
149 lines (121 loc) · 4.03 KB
/
mysql_upgrade.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
---
- hosts: all
any_errors_fatal: yes
tasks:
- vars_prompt:
- name: username
prompt: "What is your username?"
private: no
- name: password
prompt: "What is your password?"
- name: verify cluster is healthy
shell: "/opt/tools/check_cluster.sh"
run_once: true
failed_when: health_result.rc == 0
- name: Capture Master Node
shell: "/opt/tools/get_master.sh"
changed_when: false
run_once: true
register: master_node_result
failed_when: master_node_result.stdout == ""
- set_fact:
master_node: "{{ master_node_result.stdout }}"
- name: get rid of removed parameters on my.cnf
lineinfile:
path: /etc/my.cnf
regexp: '^({{ item }})'
line: '#Removed for upgrade - \1'
backrefs: yes
with_items:
- old_passwords
- innodb_additional_mem_pool_size
- name: downtime alerts
shell: "/usr/local/bin/downtime.sh --host='{{ ansible_hostname }}' --service=\"{{ item }}\" --comment='Downtime services for Upgrade'"
with_items: [ 'Slave Lag', 'MySQL status' ]
delegate_to: nagios.example.com
- hosts: all
serial: 1
any_errors_fatal: yes
tasks:
- name: Upgrade slaves
block:
- name: Take slave offline
become: yes
shell: "/opt/tools/offline_server.sh {{ ansible_hostname }}"
- name: stop MySQL
service:
name: mysql
state: stopped
- name: remove old packages
shell: "rpm -qa | grep Percona-Server | xargs rpm -e --nodeps"
- name: remove old xtrabackup
package:
name: percona-xtrabackup
state: absent
- name: Install MySQL 5.7
package:
name:
- Percona-Server-server-57
- Percona-Server-client-57
- Percona-Server-shared-57
- percona-xtrabackup-24
state: present
- name: start MySQL
service:
name: mysql
state: started
- name: run mysql_upgrade
shell: "mysql_upgrade -u{{ mysql_user }} -p{{ mysql_password }}"
- name: restart MySQL
service:
name: mysql
state: restarted
when: master_node != ansible_hostname
- hosts: all
tasks:
- name: Upgrade master
block:
- name: Switch master
shell: "/opt/tools/switch --new-master=db2"
- name: Take old master offline
become: yes
shell: "/opt/tools/offline_server.sh {{ ansible_hostname }}"
- name: stop MySQL
service:
name: mysql
state: stopped
- name: remove old packages
shell: "rpm -qa | grep Percona-Server | xargs rpm -e --nodeps"
- name: remove old xtrabackup
package:
name: percona-xtrabackup
state: absent
- name: Install MySQL 5.7
package:
name:
- Percona-Server-server-57
- Percona-Server-client-57
- Percona-Server-shared-57
- percona-xtrabackup-24
state: present
- name: start MySQL
service:
name: mysql
state: started
- name: run mysql_upgrade
shell: "mysql_upgrade -u{{ mysql_user }} -p{{ mysql_password }}"
- name: restart MySQL
service:
name: mysql
state: restarted
- name: sleep for 60 s to give alerts time to recover
wait_for: timeout=60
- name: Ensure the cluster is healthy
shell: "/opt/tools/check_cluster.sh"
register: health_result
failed_when: health_result.rc == 0
- name: cancel downtime alerts
shell: "/usr/local/bin/downtime.sh --cancel --host='{{ ansible_hostname }}' --service=\"{{ item }}\" --comment='Downtime services for Upgrade'"
with_items: [ 'Slave Lag', 'MySQL status' ]
delegate_to: nagios.example.com
when: master_node == ansible_hostname