forked from fauust/ansible-role-mariadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplication_replica.yml
54 lines (49 loc) · 1.71 KB
/
replication_replica.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
---
- name: Check replica replication status
mysql_replication:
mode: getreplica
login_unix_socket: "{{ mariadb_unix_socket }}"
register: replica
no_log: true
# For the moment, we have to use a sql command.
# In ansible 2.10, we should be able to use mysql_replication module.
# See https://github.com/ansible/ansible/pull/62648 (and below)
- name: Configure replication on the replica
command: |
/usr/bin/mariadb -e "CHANGE MASTER TO master_host='{{ mariadb_replication_master_ip }}',
master_user='{{ item.name }}', master_password='{{ item.password }}', master_use_gtid=slave_pos"
loop: "{{ mariadb_replication_user }}"
when:
- not replica.Is_Replica
no_log: true
# # Following (not tested) should work on ansible 2.10
# - name: Configure replication on the replica
# mysql_replication:
# mode: changemaster
# master_host: "{{ mariadb_replication_master_ip }}"
# master_user: "{{ item.name }}"
# master_password: "{{ item.password }}"
# master_use_gtid: "{{ mariadb_replication_gtid | default('slave_pos') }}
# login_unix_socket: "{{ mariadb_unix_socket }}"
# loop: "{{ mariadb_replication_user }}"
# when:
# - not replica.Is_Slave
# no_log: true
- name: Reset replica replication
mysql_replication:
mode: resetreplica
login_unix_socket: "{{ mariadb_unix_socket }}"
when:
- not replica.Is_Replica
- name: Check replica replication status (second time)
mysql_replication:
mode: getreplica
login_unix_socket: "{{ mariadb_unix_socket }}"
register: replica2
no_log: true
- name: Start replica replication
mysql_replication:
mode: startreplica
login_unix_socket: "{{ mariadb_unix_socket }}"
when:
- replica2.Slave_IO_Running == "No"