Few improvements(#33)
* README update * Remove useless legacy files * Small refactoring for Galera Cluster * Modern Ansible * Some changes on travis + Vagrant * Help debug: display all facts * Fix galera config for dockerpull/35/head
parent
1ec3b388a0
commit
1ebc0e9391
18
.travis.yml
18
.travis.yml
|
@ -1,13 +1,13 @@
|
||||||
env:
|
env:
|
||||||
- PLATFORM='docker-stretch-default-mariadb-master' ANSIBLE_VERSION='ansible>=2.5,<2.6'
|
- PLATFORM='docker-stretch-default-master' ANSIBLE_VERSION='ansible>=2.5,<2.6'
|
||||||
- PLATFORM='docker-stretch-upstream-mariadb-master' ANSIBLE_VERSION='ansible>=2.5,<2.6'
|
- PLATFORM='docker-stretch-upstream-master' ANSIBLE_VERSION='ansible>=2.5,<2.6'
|
||||||
- PLATFORM='docker-stretch-upstream-mariadbgalera-1' ANSIBLE_VERSION='ansible>=2.5,<2.6'
|
- PLATFORM='docker-stretch-upstream-galera-1' ANSIBLE_VERSION='ansible>=2.5,<2.6'
|
||||||
- PLATFORM='docker-stretch-default-mariadb-master' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
- PLATFORM='docker-stretch-default-master' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
||||||
- PLATFORM='docker-stretch-upstream-mariadb-master' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
- PLATFORM='docker-stretch-upstream-master' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
||||||
- PLATFORM='docker-stretch-upstream-mariadbgalera-1' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
- PLATFORM='docker-stretch-upstream-galera-1' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
||||||
- PLATFORM='docker-stretch-default-mariadb-master' ANSIBLE_VERSION='ansible>=2.7,<2.7'
|
- PLATFORM='docker-stretch-default-master' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
||||||
- PLATFORM='docker-stretch-upstream-mariadb-master' ANSIBLE_VERSION='ansible>=2.7,<2.7'
|
- PLATFORM='docker-stretch-upstream-master' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
||||||
- PLATFORM='docker-stretch-upstream-mariadbgalera-1' ANSIBLE_VERSION='ansible>=2.7,<2.7'
|
- PLATFORM='docker-stretch-upstream-galera-1' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
||||||
|
|
||||||
sudo: required
|
sudo: required
|
||||||
|
|
||||||
|
|
14
README.md
14
README.md
|
@ -5,11 +5,10 @@ MariaDB (MySQL) Ansible role for Debian
|
||||||
|
|
||||||
Install and configure MariaDB (Galera Cluster). Manage replication (master/slave). Create users and databases.
|
Install and configure MariaDB (Galera Cluster). Manage replication (master/slave). Create users and databases.
|
||||||
|
|
||||||
| OS | Vendor | Origin | Managed versions |
|
| OS | Origin | MariaDB versions |
|
||||||
| --------------- | ----------------------- | --------- | ------------------------- |
|
| --------------- | --------- | ------------------------- |
|
||||||
| Debian Stretch | MariaDB | Debian | 10.1 |
|
| Debian Stretch | Debian | 10.1 |
|
||||||
| Debian Stretch | MariaDB | Upstream | 10.1 / 10.2 / 10.3 |
|
| Debian Stretch | Upstream | 10.1 / 10.2 / 10.3 / 10.4 |
|
||||||
| Debian Stretch | MariaDB Galera Cluster | Upstream | 10.1 / 10.2 |
|
|
||||||
|
|
||||||
Notes
|
Notes
|
||||||
-----
|
-----
|
||||||
|
@ -26,8 +25,7 @@ Ansible 2.5+
|
||||||
Role Variables
|
Role Variables
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
- `mariadb_origin`: origin of the package ("default" or "upstream")
|
- `mariadb_use_galera`: set true to configure and install Galera Cluster
|
||||||
- `mariadb_vendor`: "mariadb", "mariadb\_galera"
|
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
|
@ -76,7 +74,7 @@ Example Playbook
|
||||||
|
|
||||||
- hosts: servers
|
- hosts: servers
|
||||||
roles:
|
roles:
|
||||||
- { role: HanXHX.mysql, mariadb_origin: 'upstream', mariadb_vendor: 'mariadb' }
|
- { role: HanXHX.mysql, mariadb_origin: 'upstream' }
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -16,13 +16,13 @@ Vagrant.configure("2") do |config|
|
||||||
|
|
||||||
cases = [
|
cases = [
|
||||||
# Debian Stretch
|
# Debian Stretch
|
||||||
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: dk_deb_stretch, vars: {mariadb_origin: 'default', mariadb_vendor: 'mariadb' }, groups: ['master'] },
|
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: dk_deb_stretch, vars: {mariadb_origin: 'default' }, groups: ['master'] },
|
||||||
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: nil, vars: {mariadb_origin: 'default', mariadb_vendor: 'mariadb' }, groups: ['slave'] },
|
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: nil, vars: {mariadb_origin: 'default' }, groups: ['slave'] },
|
||||||
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: dk_deb_stretch, vars: {mariadb_origin: 'upstream', mariadb_vendor: 'mariadb' }, groups: ['master'] },
|
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: dk_deb_stretch, vars: {mariadb_origin: 'upstream' }, groups: ['master'] },
|
||||||
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: nil, vars: {mariadb_origin: 'upstream', mariadb_vendor: 'mariadb' }, groups: ['slave'] },
|
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['slave'] },
|
||||||
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: dk_deb_stretch, vars: {mariadb_origin: 'upstream' }, groups: ['mariadbgalera', '1'] },
|
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: dk_deb_stretch, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '1'] },
|
||||||
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['mariadbgalera', '2'] },
|
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '2'] },
|
||||||
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['mariadbgalera', '3'] },
|
{ os_name: 'stretch', vbox: vbox_deb_stretch, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '3'] },
|
||||||
]
|
]
|
||||||
|
|
||||||
cases.each_with_index do |opts,index|
|
cases.each_with_index do |opts,index|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
# Setup
|
# Setup
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
mariadb_origin: 'default'
|
mariadb_origin: 'default'
|
||||||
mariadb_vendor: 'mariadb'
|
mariadb_use_galera: false
|
||||||
mariadb_root_password: 'change_me_NOW'
|
mariadb_root_password: 'change_me_NOW'
|
||||||
mariadb_notify_restart: true
|
mariadb_notify_restart: true
|
||||||
mariadb_upstream_apt_src: false
|
mariadb_upstream_apt_src: false
|
||||||
|
@ -135,6 +135,7 @@ mariadb_key_ids: ['0xcbcb082a1bb943db', '0xf1656f24c74cd1d8']
|
||||||
# Galera
|
# Galera
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
mariadb_galera_resetup: false
|
mariadb_galera_resetup: false
|
||||||
|
mariadb_wsrep_node_address: false # Set primary node IP
|
||||||
mariadb_galera_members: []
|
mariadb_galera_members: []
|
||||||
mariadb_galera_primary_node: 'change_me' # See: https://github.com/ansible/ansible/issues/17453
|
mariadb_galera_primary_node: 'change_me' # See: https://github.com/ansible/ansible/issues/17453
|
||||||
mariadb_wsrep_stt_method: 'rsync'
|
mariadb_wsrep_stt_method: 'rsync'
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
---
|
---
|
||||||
- set_fact:
|
- name: SET_FACT | Prepare mark var
|
||||||
booboo: "{{ mariadb_datadir }}/.ansible_galera_boostrap"
|
set_fact:
|
||||||
|
__mark: "{{ mariadb_datadir }}/.ansible_galera_boostrap"
|
||||||
|
|
||||||
- name: STAT | Bootstrap mark
|
- name: STAT | Bootstrap mark
|
||||||
stat: path={{ booboo }}
|
stat:
|
||||||
|
path: "{{ __mark }}"
|
||||||
register: s
|
register: s
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
|
@ -12,7 +14,9 @@
|
||||||
mariadb_notify_restart: false
|
mariadb_notify_restart: false
|
||||||
|
|
||||||
- name: SERVICE | Stop MariaDB
|
- name: SERVICE | Stop MariaDB
|
||||||
service: name=mysql state=stopped
|
service:
|
||||||
|
name: mysql
|
||||||
|
state: stopped
|
||||||
|
|
||||||
- name: COMMAND | Bootstrap first node (systemd)
|
- name: COMMAND | Bootstrap first node (systemd)
|
||||||
command: galera_new_cluster
|
command: galera_new_cluster
|
||||||
|
@ -29,6 +33,6 @@
|
||||||
when: not s.stat.exists or mariadb_galera_resetup
|
when: not s.stat.exists or mariadb_galera_resetup
|
||||||
|
|
||||||
- name: COMMAND | Create Bootstrap mark
|
- name: COMMAND | Create Bootstrap mark
|
||||||
command: "touch {{ booboo }}"
|
command: "touch {{ __mark }}"
|
||||||
args:
|
args:
|
||||||
creates: "{{ booboo }}"
|
creates: "{{ __mark }}"
|
||||||
|
|
|
@ -7,18 +7,18 @@
|
||||||
register: galeraconfig
|
register: galeraconfig
|
||||||
|
|
||||||
- name: INCLUDE | Bootstrap first node
|
- name: INCLUDE | Bootstrap first node
|
||||||
include: 'bootstrap.yml'
|
import_tasks: 'bootstrap.yml'
|
||||||
when: inventory_hostname == mariadb_galera_primary_node
|
when: inventory_hostname == mariadb_galera_primary_node
|
||||||
|
|
||||||
- name: INCLUDE | Configure other nodes
|
- name: INCLUDE | Configure other nodes
|
||||||
include: 'nodes.yml'
|
import_tasks: 'nodes.yml'
|
||||||
when: inventory_hostname != mariadb_galera_primary_node
|
when: inventory_hostname != mariadb_galera_primary_node
|
||||||
|
|
||||||
- name: SERVICE | Restart MariaDB if needed
|
- name: SERVICE | Restart MariaDB if needed
|
||||||
service:
|
service:
|
||||||
name: mysql
|
name: mysql
|
||||||
state: restarted
|
state: restarted
|
||||||
when: >
|
when:
|
||||||
((galeraconfig or (p is defined and p.changed)) and
|
((galeraconfig or (p is defined and p.changed)) and
|
||||||
(bootstrap_run is not defined)) or
|
(bootstrap_run is not defined)) or
|
||||||
((inventory_hostname != mariadb_galera_primary_node) and
|
((inventory_hostname != mariadb_galera_primary_node) and
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: INCLUDE | Use Percona repository
|
- name: INCLUDE | Setup Percona repository
|
||||||
include: 'percona/apt.yml'
|
import_tasks: 'percona/apt.yml'
|
||||||
when: mariadb_use_percona_apt
|
when: mariadb_use_percona_apt
|
||||||
|
|
||||||
- name: INCLUDE | Install MariaDB from Debian repo
|
- name: INCLUDE | Setup MariaDB repository
|
||||||
include: 'mariadb/default.yml'
|
import_tasks: 'mariadb/upstream.yml'
|
||||||
when: mariadb_origin == 'default' and mariadb_vendor == 'mariadb'
|
|
||||||
|
|
||||||
- name: INCLUDE | Install MariaDB from MariaDB repo
|
|
||||||
include: 'mariadb/upstream.yml'
|
|
||||||
when: mariadb_origin == 'upstream'
|
when: mariadb_origin == 'upstream'
|
||||||
|
|
||||||
|
- name: INCLUDE | Install MariaDB
|
||||||
|
import_tasks: 'mariadb/default.yml'
|
||||||
|
|
||||||
- name: APT | Install few MariaDB related tools
|
- name: APT | Install few MariaDB related tools
|
||||||
apt:
|
apt:
|
||||||
pkg: "{{ mariadb_tools }}"
|
pkg: "{{ mariadb_tools }}"
|
||||||
|
|
|
@ -28,4 +28,4 @@
|
||||||
- name: APT | Install Galera
|
- name: APT | Install Galera
|
||||||
apt:
|
apt:
|
||||||
pkg: galera-3
|
pkg: galera-3
|
||||||
when: mariadb_vendor == 'mariadb_galera'
|
when: mariadb_use_galera
|
||||||
|
|
|
@ -19,6 +19,3 @@
|
||||||
apt_repository:
|
apt_repository:
|
||||||
repo: 'deb-src {{ mariadb_repository }} {{ ansible_distribution_release }} main'
|
repo: 'deb-src {{ mariadb_repository }} {{ ansible_distribution_release }} main'
|
||||||
when: mariadb_upstream_apt_src
|
when: mariadb_upstream_apt_src
|
||||||
|
|
||||||
- name: INCLUDE | Normal Install
|
|
||||||
include: default.yml
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: INCLUDE | Install
|
- name: INCLUDE | Install
|
||||||
include: install/main.yml
|
import_tasks: install/main.yml
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy configuration
|
- name: TEMPLATE | Deploy configuration
|
||||||
template:
|
template:
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
service:
|
service:
|
||||||
name: mysql
|
name: mysql
|
||||||
state: restarted
|
state: restarted
|
||||||
when: >
|
when:
|
||||||
(config.changed or extraconfig.changed) and
|
(config.changed or extraconfig.changed) and
|
||||||
not mariadb_galera_resetup
|
not mariadb_galera_resetup
|
||||||
|
|
||||||
|
@ -42,15 +42,15 @@
|
||||||
backup: yes
|
backup: yes
|
||||||
|
|
||||||
- name: INCLUDE | Galera
|
- name: INCLUDE | Galera
|
||||||
include: galera/main.yml
|
import_tasks: galera/main.yml
|
||||||
when: mariadb_vendor == 'mariadb_galera'
|
when: mariadb_use_galera
|
||||||
|
|
||||||
- name: INCLUDE | Replication
|
- name: INCLUDE | Replication
|
||||||
include: replication/main.yml
|
import_tasks: replication/main.yml
|
||||||
when: mariadb_replication_master or mariadb_replication_slave
|
when: mariadb_replication_master or mariadb_replication_slave
|
||||||
|
|
||||||
- name: INCLUDE | Secure install
|
- name: INCLUDE | Secure install
|
||||||
include: 'secure.yml'
|
import_tasks: 'secure.yml'
|
||||||
|
|
||||||
- name: SERVICE | Ensure service is started
|
- name: SERVICE | Ensure service is started
|
||||||
service:
|
service:
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: INCLUDE | Replication Master
|
- name: INCLUDE | Replication Master
|
||||||
include: master.yml
|
import_tasks: master.yml
|
||||||
when: mariadb_replication_master
|
when: mariadb_replication_master
|
||||||
|
|
||||||
- name: INCLUDE | Replication slave
|
- name: INCLUDE | Replication slave
|
||||||
include: slave.yml
|
import_tasks: slave.yml
|
||||||
when: mariadb_replication_slave
|
when: mariadb_replication_slave
|
||||||
|
|
|
@ -19,19 +19,19 @@
|
||||||
register: slave_status
|
register: slave_status
|
||||||
|
|
||||||
- name: INCLUDE | Transfert /etc/mysql/debian.cnf from master
|
- name: INCLUDE | Transfert /etc/mysql/debian.cnf from master
|
||||||
include: slave/ssh.yml
|
import_tasks: slave/ssh.yml
|
||||||
when: mariadb_slave_replicate_mysqldb or ((slave_status.failed is defined or not slave_status.Is_Slave) and mariadb_slave_import_data)
|
when: mariadb_slave_replicate_mysqldb or ((slave_status.failed is defined or not slave_status.Is_Slave) and mariadb_slave_import_data)
|
||||||
|
|
||||||
- name: INCLUDE | Import data
|
- name: INCLUDE | Import data
|
||||||
include: slave/import_data.yml
|
import_tasks: slave/import_data.yml
|
||||||
when: (slave_status.failed is defined or not slave_status.Is_Slave) and mariadb_slave_import_data
|
when: (slave_status.failed is defined or not slave_status.Is_Slave) and mariadb_slave_import_data
|
||||||
|
|
||||||
- name: INCLUDE | Configure replication
|
- name: INCLUDE | Configure replication
|
||||||
include: slave/replication.yml
|
import_tasks: slave/replication.yml
|
||||||
when: (slave_status.failed is defined or not slave_status.Is_Slave) or mariadb_slave_force_setup
|
when: (slave_status.failed is defined or not slave_status.Is_Slave) or mariadb_slave_force_setup
|
||||||
|
|
||||||
- name: INCLUDE | Transfert /etc/mysql/debian.cnf from master
|
- name: INCLUDE | Transfert /etc/mysql/debian.cnf from master
|
||||||
include: slave/debiancnf.yml
|
import_tasks: slave/debiancnf.yml
|
||||||
when: mariadb_slave_replicate_mysqldb
|
when: mariadb_slave_replicate_mysqldb
|
||||||
|
|
||||||
- name: MYSQL_REPLICATION | Get slave status
|
- name: MYSQL_REPLICATION | Get slave status
|
||||||
|
@ -41,4 +41,4 @@
|
||||||
register: slave_status
|
register: slave_status
|
||||||
|
|
||||||
- name: Configure GTID
|
- name: Configure GTID
|
||||||
include: slave/gtid.yml
|
import_tasks: slave/gtid.yml
|
||||||
|
|
|
@ -9,7 +9,10 @@
|
||||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||||
|
|
||||||
- name: LOCAL_ACTION FILE | Secure fetched file
|
- name: LOCAL_ACTION FILE | Secure fetched file
|
||||||
local_action: file path=/tmp/{{ mariadb_slave_import_from }}/debian.cnf mode=0600
|
local_action:
|
||||||
|
module: file
|
||||||
|
path: "/tmp/{{ mariadb_slave_import_from }}/debian.cnf"
|
||||||
|
mode: 0600
|
||||||
become: no
|
become: no
|
||||||
|
|
||||||
- name: COPY | Fetched file to /etc/mysql/debian.cnf
|
- name: COPY | Fetched file to /etc/mysql/debian.cnf
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
port: 22
|
port: 22
|
||||||
|
|
||||||
- name: COMMAND | Prepare backup another server
|
- name: COMMAND | Prepare backup another server
|
||||||
command: innobackupex --no-timestamp {{ mariadb_backup_dir }} creates={{ mariadb_backup_dir }}
|
command: innobackupex --no-timestamp {{ mariadb_backup_dir }}
|
||||||
|
args:
|
||||||
|
creates: "{{ mariadb_backup_dir }}"
|
||||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||||
register: backup
|
register: backup
|
||||||
|
|
||||||
|
@ -24,7 +26,8 @@
|
||||||
when: backup.changed and not mariadb_slave_replicate_mysqldb
|
when: backup.changed and not mariadb_slave_replicate_mysqldb
|
||||||
|
|
||||||
- name: MYSQL_VARIABLES | Get datadir
|
- name: MYSQL_VARIABLES | Get datadir
|
||||||
mysql_variables: variable=datadir
|
mysql_variables:
|
||||||
|
variable: datadir
|
||||||
register: datadir
|
register: datadir
|
||||||
|
|
||||||
- name: SET_FACT | related to mysql datadir
|
- name: SET_FACT | related to mysql datadir
|
||||||
|
@ -74,6 +77,8 @@
|
||||||
mariadb_master_gtid: "{{ master_gtid.stdout }}"
|
mariadb_master_gtid: "{{ master_gtid.stdout }}"
|
||||||
|
|
||||||
- name: FILE | Delete dump
|
- name: FILE | Delete dump
|
||||||
file: path={{ mariadb_backup_dir }} state=absent
|
file:
|
||||||
|
path: "{{ mariadb_backup_dir }}"
|
||||||
|
state: absent
|
||||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||||
when: mariadb_slave_import_flush_dump
|
when: mariadb_slave_import_flush_dump
|
||||||
|
|
|
@ -18,7 +18,7 @@ wsrep_cluster_name="{{ mariadb_wsrep_cluster_name }}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
# Node Configuration
|
# Node Configuration
|
||||||
wsrep_node_address="{{ mariadb_wsrep_node_address | default(ansible_default_ipv4.address) }}"
|
wsrep_node_address="{{ mariadb_wsrep_node_address | default(ansible_default_ipv4.address if ansible_default_ipv4 is defined else '127.0.0.1') }}"
|
||||||
wsrep_node_name="{{ mariadb_wsrep_node_name | default(ansible_fqdn) }}"
|
wsrep_node_name="{{ mariadb_wsrep_node_name | default(ansible_fqdn) }}"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mariadb_vendor: 'mariadb_galera'
|
mariadb_use_galera: true
|
||||||
mariadb_galera_members:
|
mariadb_galera_members:
|
||||||
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-mariadbgalera-1'
|
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-galera-1'
|
||||||
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-mariadbgalera-2'
|
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-galera-2'
|
||||||
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-mariadbgalera-3'
|
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-galera-3'
|
|
@ -1 +0,0 @@
|
||||||
mariadb_vendor: 'mysql'
|
|
|
@ -1,21 +1,37 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- hosts: all
|
- hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
pre_tasks:
|
||||||
|
- name: SETUP | Get facts
|
||||||
|
setup:
|
||||||
|
register: s
|
||||||
|
- name: DEBUG | Show facts
|
||||||
|
debug:
|
||||||
|
var: s
|
||||||
tasks:
|
tasks:
|
||||||
- apt: pkg={{ item }} state=present update_cache=yes cache_valid_time=3600
|
- name: APT | Install some packages
|
||||||
loop:
|
apt:
|
||||||
- ca-certificates
|
name: "{{ p }}"
|
||||||
- curl
|
update_cache: yes
|
||||||
- strace
|
cache_valid_time: 3600
|
||||||
- vim
|
vars:
|
||||||
|
p: ['ca-certificates', 'curl', 'strace', 'vim']
|
||||||
|
|
||||||
- hosts: master
|
- hosts: master
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
tasks:
|
tasks:
|
||||||
- copy: src=import1.sql dest=/tmp/import1.sql
|
- name: COPY | Deploy first dump
|
||||||
|
copy:
|
||||||
|
src: import1.sql
|
||||||
|
dest: /tmp/import1.sql
|
||||||
register: c
|
register: c
|
||||||
- mysql_db: name={{ item }} state=import target=/tmp/import1.sql
|
- name: MYSQL_DB | Import first dump
|
||||||
|
mysql_db:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: import
|
||||||
|
target: /tmp/import1.sql
|
||||||
loop: ['testrepl', 'norepl']
|
loop: ['testrepl', 'norepl']
|
||||||
when: c.changed
|
when: c.changed
|
||||||
|
|
||||||
|
@ -25,7 +41,8 @@
|
||||||
shell: getent hosts {{ ansible_hostname | replace ('slave', 'master') }} | cut -d ' ' -f 1
|
shell: getent hosts {{ ansible_hostname | replace ('slave', 'master') }} | cut -d ' ' -f 1
|
||||||
register: ip
|
register: ip
|
||||||
changed_when: false
|
changed_when: false
|
||||||
- set_fact:
|
- name: SET_FACT | Apply some configuration
|
||||||
|
set_fact:
|
||||||
# MariaDB don't read /etc/hosts (from vagrant host plugin)
|
# MariaDB don't read /etc/hosts (from vagrant host plugin)
|
||||||
mariadb_replication_host: "{{ ip.stdout }}"
|
mariadb_replication_host: "{{ ip.stdout }}"
|
||||||
# Need this to use vagrant 'delegate_to'
|
# Need this to use vagrant 'delegate_to'
|
||||||
|
@ -33,27 +50,35 @@
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
tasks:
|
tasks:
|
||||||
- copy: src=import2.sql dest=/tmp/import2.sql
|
- name: COPY | Deploy dump
|
||||||
|
copy:
|
||||||
|
src: import2.sql
|
||||||
|
dest: /tmp/import2.sql
|
||||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||||
register: c
|
register: c
|
||||||
- mysql_db: name={{ item }} state=import target=/tmp/import2.sql
|
- name: MYSQL_DB | Import another dump
|
||||||
|
mysql_db:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: import
|
||||||
|
target: /tmp/import2.sql
|
||||||
loop: ['testrepl', 'norepl']
|
loop: ['testrepl', 'norepl']
|
||||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||||
when: c.changed
|
when: c.changed
|
||||||
- mysql_replication: mode=getslave
|
- name: MYSQL_REPLICATION | Get slave infos
|
||||||
|
mysql_replication:
|
||||||
|
mode: getslave
|
||||||
register: slave
|
register: slave
|
||||||
- fail: msg="Slave issue"
|
- name: FAIL | if slave threads are not running
|
||||||
|
fail:
|
||||||
|
msg: "Slave issue"
|
||||||
when: slave.Slave_IO_Running != 'Yes' or slave.Slave_SQL_Running != 'Yes'
|
when: slave.Slave_IO_Running != 'Yes' or slave.Slave_SQL_Running != 'Yes'
|
||||||
|
|
||||||
- hosts: mariadbgalera
|
- hosts: galera
|
||||||
vars:
|
|
||||||
mariadb_galera_primary_node: '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-mariadbgalera-1'
|
|
||||||
mariadb_wsrep_node_address: "{{ ansible_all_ipv4_addresses[0] }}"
|
|
||||||
mariadb_version: '10.1'
|
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
- set_fact:
|
- name: SET_FACT | Apply some configuration
|
||||||
mariadb_wsrep_node_address: "{{ ansible_eth1.ipv4.address }}"
|
set_fact:
|
||||||
when: not is_docker
|
mariadb_galera_primary_node: '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-galera-1'
|
||||||
|
mariadb_wsrep_node_address: "{{ '127.0.0.1' if is_docker else ansible_eth1.ipv4.address }}"
|
||||||
|
mariadb_version: '10.1'
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
|
|
||||||
|
|
||||||
DIR=$( dirname $0 )
|
|
||||||
INVENTORY_FILE="localhost,"
|
|
||||||
PLAYBOOK="$DIR/travis.yml"
|
|
||||||
|
|
||||||
set -ev
|
|
||||||
|
|
||||||
# Check syntax
|
|
||||||
ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK
|
|
||||||
|
|
||||||
# Check role
|
|
||||||
ansible-playbook -i $INVENTORY_FILE -c local -e "{ mariadb_vendor: $VENDOR, mariadb_origin: $ORIGIN }" --sudo -vv $PLAYBOOK
|
|
||||||
|
|
||||||
# Check indempotence
|
|
||||||
ansible-playbook -i $INVENTORY_FILE -c local -e "{ mariadb_vendor: $VENDOR, mariadb_origin: $ORIGIN }" --sudo -vv $PLAYBOOK > idempot.txt
|
|
||||||
grep -q 'changed=0.*failed=0' idempot.txt \
|
|
||||||
&& (echo 'Idempotence test: pass' && exit 0) \
|
|
||||||
|| (echo 'Idempotence test: FAIL' && cat idempot.txt && exit 1)
|
|
|
@ -1,15 +0,0 @@
|
||||||
---
|
|
||||||
|
|
||||||
- hosts: all
|
|
||||||
vars:
|
|
||||||
mariadb_replication_master: true
|
|
||||||
mariadb_bind_address: '{{ ansible_eth0.ipv4.address }}'
|
|
||||||
mariadb_galera_members:
|
|
||||||
- '{{ ansible_eth0.ipv4.address }}'
|
|
||||||
mariadb_galera_primary_node: 'localhost'
|
|
||||||
roles:
|
|
||||||
- ../../
|
|
||||||
post_tasks:
|
|
||||||
- name: TEST | SHELL | Test mysql
|
|
||||||
shell: mysql -e "SHOW DATABASES;"
|
|
||||||
changed_when: false
|
|
Loading…
Reference in New Issue