2019-09-27 15:29:34 +02:00
|
|
|
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
# Preparation:
|
|
|
|
- name: Create user for replication
|
|
|
|
shell: "echo \"GRANT REPLICATION SLAVE ON *.* TO '{{ replication_user }}'@'localhost' IDENTIFIED BY '{{ replication_pass }}'; FLUSH PRIVILEGES;\" | mysql -P {{ master_port }} -h 127.0.0.1"
|
|
|
|
|
|
|
|
- name: Create test database
|
|
|
|
mysql_db:
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: '{{ master_port }}'
|
|
|
|
state: present
|
|
|
|
name: '{{ test_db }}'
|
|
|
|
|
|
|
|
- name: Dump all databases from the master
|
|
|
|
shell: 'mysqldump -P {{ master_port }} -h 127.0.01 --all-databases --master-data=2 > {{ dump_path }}'
|
|
|
|
|
|
|
|
- name: Restore the dump to the standby
|
|
|
|
shell: 'mysql -P {{ standby_port }} -h 127.0.0.1 < {{ dump_path }}'
|
|
|
|
|
|
|
|
# Test getmaster mode:
|
|
|
|
- name: Get master status
|
|
|
|
mysql_replication:
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: "{{ master_port }}"
|
|
|
|
mode: getmaster
|
|
|
|
register: master_status
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- master_status.Is_Master == true
|
|
|
|
- master_status.Position != 0
|
|
|
|
- master_status is not changed
|
|
|
|
|
|
|
|
# Test changemaster mode:
|
|
|
|
- name: Run replication
|
|
|
|
mysql_replication:
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: "{{ standby_port }}"
|
|
|
|
mode: changemaster
|
|
|
|
master_host: 127.0.0.1
|
|
|
|
master_port: "{{ master_port }}"
|
|
|
|
master_user: "{{ replication_user }}"
|
|
|
|
master_password: "{{ replication_pass }}"
|
|
|
|
master_log_file: mysql-bin.000001
|
|
|
|
master_log_pos: '{{ master_status.Position }}'
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
|
|
|
|
- name: Run replication via shell
|
|
|
|
shell: 'echo "START SLAVE;" | mysql -P {{ standby_port }} -h 127.0.0.1'
|
|
|
|
|
|
|
|
# Test getslave mode:
|
|
|
|
- name: Get standby status
|
|
|
|
mysql_replication:
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: "{{ standby_port }}"
|
|
|
|
mode: getslave
|
|
|
|
register: slave_status
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- slave_status.Is_Slave == true
|
|
|
|
- slave_status.Master_Host == '127.0.0.1'
|
|
|
|
- slave_status.Exec_Master_Log_Pos == master_status.Position
|
|
|
|
- slave_status.Master_Port == {{ master_port }}
|
|
|
|
- slave_status.Last_IO_Errno == 0
|
|
|
|
- slave_status.Last_IO_Error == ''
|
|
|
|
- slave_status is not changed
|
2019-10-01 08:29:40 +02:00
|
|
|
|
|
|
|
###############
|
|
|
|
# Finish tests
|
|
|
|
|
|
|
|
- name: Stop replication via shell
|
|
|
|
shell: 'echo "STOP SLAVE;" | mysql -P {{ standby_port }} -h 127.0.0.1'
|