mariadb/tasks/replication.yml
2019-04-14 20:27:36 +02:00

59 lines
2.0 KiB
YAML

---
- name: Ensure replication user exists on master.
mysql_user:
name: "{{ mysql_replication_user.name }}"
host: "{{ mysql_replication_user.host | default('%') }}"
password: "{{ mysql_replication_user.password }}"
priv: "{{ mysql_replication_user.priv | default('*.*:REPLICATION SLAVE,REPLICATION CLIENT') }}"
state: present
when:
- mysql_replication_role == 'master'
- mysql_replication_user
- mysql_replication_master != ''
tags: ['skip_ansible_galaxy']
- name: Check slave replication status.
mysql_replication:
mode: getslave
login_user: "{{ mysql_replication_user.name }}"
login_password: "{{ mysql_replication_user.password }}"
ignore_errors: true
register: slave
when:
- mysql_replication_role == 'slave'
- mysql_replication_master != ''
tags: ['skip_ansible_galaxy']
- name: Check master replication status.
mysql_replication: mode=getmaster
delegate_to: "{{ mysql_replication_master }}"
register: master
when:
- (slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave is failed)
- mysql_replication_role == 'slave'
- mysql_replication_master != ''
tags: ['skip_ansible_galaxy']
- name: Configure replication on the slave.
mysql_replication:
mode: changemaster
master_host: "{{ mysql_replication_master }}"
master_user: "{{ mysql_replication_user.name }}"
master_password: "{{ mysql_replication_user.password }}"
master_log_file: "{{ master.File }}"
master_log_pos: "{{ master.Position }}"
ignore_errors: true
when:
- (slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave is failed)
- mysql_replication_role == 'slave'
- mysql_replication_master != ''
- mysql_replication_user
- name: Start replication.
mysql_replication: mode=startslave
when:
- (slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave is failed)
- mysql_replication_role == 'slave'
- mysql_replication_master != ''
tags: ['skip_ansible_galaxy']