2019-09-27 15:29:34 +02:00
|
|
|
# We run two servers listening different ports
|
|
|
|
# to be able to check replication (one server for master, another for standby).
|
|
|
|
|
2019-10-01 08:29:40 +02:00
|
|
|
- name: Install MariaDB repo
|
|
|
|
yum_repository:
|
|
|
|
name: MariaDB
|
|
|
|
description: MariaDB official repo
|
|
|
|
baseurl: http://yum.mariadb.org/10.1/centos7-amd64
|
|
|
|
gpgkey: https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
|
|
|
|
gpgcheck: yes
|
|
|
|
|
2019-09-27 15:29:34 +02:00
|
|
|
- name: Install MariaDB packages on RedHat family OS
|
|
|
|
yum:
|
|
|
|
name: "{{ item }}"
|
|
|
|
enablerepo: epel
|
|
|
|
loop:
|
2019-10-01 08:29:40 +02:00
|
|
|
- MariaDB-server
|
|
|
|
- MariaDB-client
|
2019-09-27 15:29:34 +02:00
|
|
|
when: ansible_os_family == 'RedHat'
|
|
|
|
|
|
|
|
- name: Create directories for standby
|
|
|
|
file:
|
|
|
|
state: directory
|
|
|
|
path: "{{ item }}"
|
|
|
|
owner: mysql
|
|
|
|
group: mysql
|
|
|
|
loop:
|
2019-10-01 08:29:40 +02:00
|
|
|
- "{{ master_datadir }}"
|
2019-09-27 15:29:34 +02:00
|
|
|
- "{{ standby_datadir }}"
|
|
|
|
- "{{ standby_logdir }}"
|
2019-10-01 08:29:40 +02:00
|
|
|
- "{{ default_logdir }}"
|
2019-09-27 15:29:34 +02:00
|
|
|
|
|
|
|
- name: Copy cnf template
|
|
|
|
template:
|
|
|
|
src: my.cnf.j2
|
|
|
|
dest: /etc/my.cnf
|
|
|
|
owner: mysql
|
|
|
|
group: mysql
|
|
|
|
force: yes
|
|
|
|
|
2019-10-01 08:29:40 +02:00
|
|
|
- name: Initialize DBs
|
|
|
|
shell: 'mysql_install_db --user=mysql --datadir={{ item }}'
|
|
|
|
loop:
|
|
|
|
- '{{ master_datadir }}'
|
|
|
|
- '{{ standby_datadir }}'
|
2019-09-27 15:29:34 +02:00
|
|
|
|
|
|
|
- name: Start services
|
2019-10-01 08:29:40 +02:00
|
|
|
shell: 'mysqld_multi --log=/var/log/mariadb/mariadb.log start 1,2'
|
2019-09-27 15:29:34 +02:00
|
|
|
|
|
|
|
- name: Pause
|
|
|
|
pause: seconds=3
|
|
|
|
|
|
|
|
########### For painful debug uncomment the lines below ##
|
|
|
|
#- name: DEBUG Check stratup log
|
|
|
|
# shell: cat /var/log/mariadb/mariadb.log
|
|
|
|
|
2019-10-01 08:29:40 +02:00
|
|
|
#- name: DEBUG Check mysql_safe err log
|
|
|
|
# shell: cat '{{ mysql_safe_err_log }}'
|
|
|
|
|
2019-09-27 15:29:34 +02:00
|
|
|
#- name: DEBUG Check processes
|
|
|
|
# shell: 'ps aux | grep mysqld | grep -v "grep\|root"'
|
|
|
|
|
|
|
|
#- name: DEBUG
|
|
|
|
# yum: name=net-tools
|
|
|
|
|
|
|
|
#- name: DEBUG
|
|
|
|
# shell: "netstat -ntpl"
|
|
|
|
|
|
|
|
#- name: DEBUG
|
|
|
|
# shell: cat /etc/my.cnf
|
|
|
|
##########################################################
|
|
|
|
|
|
|
|
- name: Check connection to the master
|
|
|
|
shell: 'echo "SHOW DATABASES;" | mysql -P {{ master_port }} -h 127.0.0.1'
|
|
|
|
|
|
|
|
- name: Check connection to the standby
|
|
|
|
shell: "echo \"SHOW VARIABLES LIKE 'datadir';\" | mysql -P {{ standby_port }} -h 127.0.0.1"
|