2019-09-27 15:29:34 +02:00
|
|
|
# We run two servers listening different ports
|
2019-11-15 23:06:27 +01:00
|
|
|
# to be able to check replication (one server for primary, another for replica).
|
|
|
|
|
|
|
|
- name: Include distribution specific variables
|
|
|
|
include_vars: "{{ lookup('first_found', params) }}"
|
|
|
|
vars:
|
|
|
|
params:
|
|
|
|
files:
|
|
|
|
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml"
|
|
|
|
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
|
|
|
|
- "{{ ansible_facts.distribution }}.yml"
|
|
|
|
- "{{ ansible_facts.os_family }}.yml"
|
|
|
|
- default.yml
|
|
|
|
paths:
|
|
|
|
- vars
|
2019-09-27 15:29:34 +02:00
|
|
|
|
2019-10-01 08:29:40 +02:00
|
|
|
- name: Install MariaDB repo
|
|
|
|
yum_repository:
|
|
|
|
name: MariaDB
|
|
|
|
description: MariaDB official repo
|
2019-10-19 13:10:35 +02:00
|
|
|
baseurl: "{{ repo_link }}"
|
|
|
|
gpgkey: "{{ repo_gpgkey }}"
|
2019-10-01 08:29:40 +02:00
|
|
|
gpgcheck: yes
|
2019-10-19 13:10:35 +02:00
|
|
|
notify: cleanup mariadb
|
2019-10-01 08:29:40 +02:00
|
|
|
|
2019-11-15 23:06:27 +01:00
|
|
|
- name: Install MariaDB packages
|
2019-09-27 15:29:34 +02:00
|
|
|
yum:
|
2019-10-23 15:50:31 +02:00
|
|
|
name: "{{ mariadb_packages }}"
|
2019-11-15 23:06:27 +01:00
|
|
|
enablerepo: "{{ mariadb_enable_repo | default(omit) }}"
|
2019-10-19 13:10:35 +02:00
|
|
|
notify: cleanup mariadb
|
2019-09-27 15:29:34 +02:00
|
|
|
|
2019-10-19 13:10:35 +02:00
|
|
|
- name: Create directories for instances
|
2019-09-27 15:29:34 +02:00
|
|
|
file:
|
|
|
|
state: directory
|
|
|
|
path: "{{ item }}"
|
|
|
|
owner: mysql
|
|
|
|
group: mysql
|
|
|
|
loop:
|
2019-11-15 23:06:27 +01:00
|
|
|
- "{{ primary_db.datadir }}"
|
|
|
|
- "{{ primary_db.logdir }}"
|
|
|
|
- "{{ replica_db.datadir }}"
|
|
|
|
- "{{ replica_db.logdir }}"
|
2019-10-19 13:10:35 +02:00
|
|
|
notify: cleanup mariadb
|
2019-09-27 15:29:34 +02:00
|
|
|
|
2019-11-15 23:06:27 +01:00
|
|
|
- name: Copy configuration templates
|
|
|
|
template:
|
|
|
|
src: "{{ 'my' ~ item ~ '.j2' }}"
|
|
|
|
dest: /etc/my.cnf.d/my{{ item }}.cnf
|
|
|
|
owner: mysql
|
|
|
|
group: mysql
|
|
|
|
force: yes
|
|
|
|
when: ansible_facts.distribution_major_version is version('7', '==')
|
|
|
|
loop:
|
|
|
|
- '{{ primary_db.name }}'
|
|
|
|
- '{{ replica_db.name }}'
|
|
|
|
|
|
|
|
- name: Copy configuration template
|
2019-09-27 15:29:34 +02:00
|
|
|
template:
|
|
|
|
src: my.cnf.j2
|
|
|
|
dest: /etc/my.cnf
|
|
|
|
owner: mysql
|
|
|
|
group: mysql
|
|
|
|
force: yes
|
2019-11-15 23:06:27 +01:00
|
|
|
when: ansible_facts.distribution_major_version is version('8', '==')
|
2019-09-27 15:29:34 +02:00
|
|
|
|
2019-10-01 08:29:40 +02:00
|
|
|
- name: Initialize DBs
|
|
|
|
shell: 'mysql_install_db --user=mysql --datadir={{ item }}'
|
|
|
|
loop:
|
2019-11-15 23:06:27 +01:00
|
|
|
- '{{ primary_db.datadir }}'
|
|
|
|
- '{{ replica_db.datadir }}'
|
2019-09-27 15:29:34 +02:00
|
|
|
|
|
|
|
- name: Start services
|
2019-11-15 23:06:27 +01:00
|
|
|
service:
|
|
|
|
name: mariadb@{{ item }}
|
|
|
|
state: started
|
|
|
|
loop:
|
|
|
|
- "{{ primary_db.name }}"
|
|
|
|
- "{{ replica_db.name }}"
|
2019-09-27 15:29:34 +02:00
|
|
|
|
2019-11-15 23:06:27 +01:00
|
|
|
- pause:
|
|
|
|
seconds: 3
|
2019-09-27 15:29:34 +02:00
|
|
|
|
|
|
|
########### 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
|
|
|
|
##########################################################
|
|
|
|
|
2019-11-15 23:06:27 +01:00
|
|
|
- name: Check connection to the primary
|
|
|
|
shell: 'echo "SHOW DATABASES;" | mysql -P {{ primary_db.port }} -h 127.0.0.1'
|
2019-09-27 15:29:34 +02:00
|
|
|
|
2019-11-15 23:06:27 +01:00
|
|
|
- name: Check connection to the replica
|
|
|
|
shell: "echo \"SHOW VARIABLES LIKE 'datadir';\" | mysql -P {{ replica_db.port }} -h 127.0.0.1"
|