- name: Check if slave is already configured for replication
mysql_replication: mode=getslave
register: slave
ignore_errors: true # on the first run, this will error because not replicating yet
when: ansible_default_ipv4.address != mysql_master_ip
- name: Get the current master server's replication status
mysql_replication: "mode=getmaster login_user='{{ mysql_replication_user }}' login_password='{{ mysql_replication_pass }}' login_host='{{ mysql_master_ip }}'"
register: mysql_repl_stat
delegate_to: "{{ mysql_master_name }}"
when: ansible_default_ipv4.address != mysql_master_ip
- name: ensure mysql replication
when: "slave|failed and ansible_default_ipv4.address != mysql_master_ip
command: "
/usr/bin/mysql -u {{ mysql_user }} -p{{ mysql_pass }} -e
\"
STOP SLAVE;
RESET MASTER;
SET GLOBAL gtid_purged='{{ mysql_repl_stat.Executed_Gtid_Set }}';
CHANGE MASTER TO MASTER_HOST='{{ mysql_master_ip }}', MASTER_USER='{{ mysql_replication_user }}', MASTER_PASSWORD='{{ mysql_replication_pass }}', MASTER_AUTO_POSITION=1;
START SLAVE;
\"