Compare commits
18 Commits
d2ec2eaa28
...
1d062b1d00
Author | SHA1 | Date |
---|---|---|
Emilien Mantel | 1d062b1d00 | |
Emilien Mantel | cd9cc5c485 | |
Emilien Mantel | 798107612d | |
Emilien Mantel | 620d32320a | |
Emilien Mantel | 6d0eb53d60 | |
Emilien Mantel | 8266a073a0 | |
Emilien Mantel | ef4a450a17 | |
Emilien Mantel | 7606a76d23 | |
Emilien Mantel | 906319e18a | |
Emilien Mantel | 42b29be121 | |
Emilien Mantel | dd4ae02ffa | |
Emilien Mantel | a8f89f47b2 | |
Emilien Mantel | 186a32d5ac | |
Emilien Mantel | 53fb3caa91 | |
Emilien Mantel | ed8949684f | |
Emilien Mantel | 5d2e31a98e | |
Emilien Mantel | 2823b6de00 | |
Emilien Mantel | dd776e653f |
|
@ -6,6 +6,7 @@ skip_list: []
|
||||||
|
|
||||||
exclude_paths:
|
exclude_paths:
|
||||||
- venv/
|
- venv/
|
||||||
|
- tests/ # TODO: Remove this line when tests are migrated to molecule
|
||||||
- .github/
|
- .github/
|
||||||
|
|
||||||
offline: false
|
offline: false
|
||||||
|
|
|
@ -14,7 +14,6 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
scenario:
|
scenario:
|
||||||
- debian12_galera
|
|
||||||
- debian12_master_slave
|
- debian12_master_slave
|
||||||
- debian12_upstream
|
- debian12_upstream
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
.vagrant*
|
||||||
*.swp
|
*.swp
|
||||||
*.retry
|
*.retry
|
||||||
/.idea
|
/.idea
|
||||||
|
|
|
@ -7,3 +7,4 @@ rules:
|
||||||
|
|
||||||
ignore:
|
ignore:
|
||||||
- /venv
|
- /venv
|
||||||
|
- /tests # TODO: Remove this line when tests are migrated to molecule
|
||||||
|
|
|
@ -16,7 +16,9 @@ If you need to manage previous Debian versions, please use the [latest managed v
|
||||||
Notes
|
Notes
|
||||||
-----
|
-----
|
||||||
|
|
||||||
* Galera Cluster is experimental. Feel free to test it and report issues.
|
* Galera Cluster is experimental
|
||||||
|
* Due to Vagrant + Docker limitation (private network), replication/galera can't be checked with Travis
|
||||||
|
* If you need to test this role with Vagrant, you must install hostmanager plugin: `vagrant plugin install vagrant-hostmanager`
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
# -*- mode: ruby -*-
|
||||||
|
# vi: set ft=ruby :
|
||||||
|
# vi: set tabstop=2 :
|
||||||
|
# vi: set shiftwidth=2 :
|
||||||
|
|
||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
|
||||||
|
vbox_deb_buster = 'debian/buster64'
|
||||||
|
dk_deb_buster = 'hanxhx/vagrant-ansible:debian10'
|
||||||
|
|
||||||
|
vbox_deb_bullseye = 'debian/bullseye64'
|
||||||
|
dk_deb_bullseye = 'hanxhx/vagrant-ansible:debian11'
|
||||||
|
|
||||||
|
config.hostmanager.enabled = true
|
||||||
|
config.hostmanager.manage_host = false
|
||||||
|
config.hostmanager.manage_guest = true
|
||||||
|
config.hostmanager.ignore_private_ip = false
|
||||||
|
config.hostmanager.include_offline = false
|
||||||
|
|
||||||
|
cases = [
|
||||||
|
# ========================
|
||||||
|
# Debian Buster (10)
|
||||||
|
# ========================
|
||||||
|
|
||||||
|
# Default replication
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: dk_deb_buster, vars: {mariadb_origin: 'default' }, groups: ['master'] },
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: nil, vars: {mariadb_origin: 'default' }, groups: ['slave'] },
|
||||||
|
|
||||||
|
# Upstream replication
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: dk_deb_buster, vars: {mariadb_origin: 'upstream' }, groups: ['master'] },
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['slave'] },
|
||||||
|
|
||||||
|
# Galera Debian
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: dk_deb_buster, vars: {mariadb_origin: 'default' }, groups: ['galera', '1'] },
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: nil, vars: {mariadb_origin: 'default' }, groups: ['galera', '2'] },
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: nil, vars: {mariadb_origin: 'default' }, groups: ['galera', '3'] },
|
||||||
|
|
||||||
|
# Galera Upstream
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: dk_deb_buster, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '1'] },
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '2'] },
|
||||||
|
{ os_name: 'buster', vbox: vbox_deb_buster, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '3'] },
|
||||||
|
|
||||||
|
# ========================
|
||||||
|
# Debian Bullseye (11)
|
||||||
|
# ========================
|
||||||
|
|
||||||
|
# Default replication
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: dk_deb_bullseye, vars: {mariadb_origin: 'default' }, groups: ['master'] },
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: nil, vars: {mariadb_origin: 'default' }, groups: ['slave'] },
|
||||||
|
|
||||||
|
# Upstream replication
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: dk_deb_bullseye, vars: {mariadb_origin: 'upstream' }, groups: ['master'] },
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['slave'] },
|
||||||
|
|
||||||
|
# Galera Debian
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: dk_deb_bullseye, vars: {mariadb_origin: 'default' }, groups: ['galera', '1'] },
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: nil, vars: {mariadb_origin: 'default' }, groups: ['galera', '2'] },
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: nil, vars: {mariadb_origin: 'default' }, groups: ['galera', '3'] },
|
||||||
|
|
||||||
|
# Galera Upstream
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: dk_deb_bullseye, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '1'] },
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '2'] },
|
||||||
|
{ os_name: 'bullseye', vbox: vbox_deb_bullseye, docker: nil, vars: {mariadb_origin: 'upstream' }, groups: ['galera', '3'] },
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
cases.each_with_index do |opts,index|
|
||||||
|
name = 'docker-' + opts[:os_name] + '-' + opts[:vars].map{|k,v| "#{v}"}.join('-') + '-' + opts[:groups].join('-')
|
||||||
|
iplsb = 10 + index
|
||||||
|
ip = '192.168.201.' + iplsb.to_s
|
||||||
|
next if opts[:docker].nil?
|
||||||
|
|
||||||
|
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||||
|
config.vm.define name do |m|
|
||||||
|
m.vm.network "private_network", ip: ip
|
||||||
|
m.vm.provider "docker" do |d|
|
||||||
|
d.image = opts[:docker]
|
||||||
|
d.remains_running = true
|
||||||
|
d.has_ssh = true
|
||||||
|
end
|
||||||
|
|
||||||
|
m.vm.provision "ansible" do |ansible|
|
||||||
|
ansible.playbook = "tests/test.yml"
|
||||||
|
ansible.verbose = 'vv'
|
||||||
|
ansible.become = true
|
||||||
|
ansible.extra_vars = opts[:vars].merge({ mariadb_debug_role: true, is_docker: true })
|
||||||
|
ansible.groups = { opts[:groups][0] => name }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
cases.each_with_index do |opts,index|
|
||||||
|
name = 'vbox-' + opts[:os_name] + '-' + opts[:vars].map{|k,v| "#{v}"}.join('-') + '-' + opts[:groups].join('-')
|
||||||
|
iplsb = 10 + index
|
||||||
|
ip = '192.168.200.' + iplsb.to_s
|
||||||
|
config.vm.define name do |m|
|
||||||
|
m.vm.hostname = name
|
||||||
|
m.vm.box = opts[:vbox]
|
||||||
|
m.vm.network "private_network", ip: ip
|
||||||
|
m.vm.provider "virtualbox" do |v|
|
||||||
|
v.cpus = 1
|
||||||
|
v.memory = 512
|
||||||
|
end
|
||||||
|
|
||||||
|
m.vm.provision "ansible" do |ansible|
|
||||||
|
ansible.playbook = "tests/test.yml"
|
||||||
|
ansible.verbose = 'vv'
|
||||||
|
ansible.become = true
|
||||||
|
ansible.extra_vars = opts[:vars].merge({ mariadb_debug_role: true, is_docker: false })
|
||||||
|
ansible.groups = { opts[:groups][0] => name }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -121,7 +121,7 @@ mariadb_upstream_version: '11.4'
|
||||||
# Galera
|
# Galera
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
mariadb_galera_resetup: false
|
mariadb_galera_resetup: false
|
||||||
mariadb_wsrep_node_address: '{{ ansible_default_ipv4.address if ansible_default_ipv4 is defined else "127.0.0.1" }}'
|
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_sst_method: 'rsync'
|
mariadb_wsrep_sst_method: 'rsync'
|
||||||
|
|
|
@ -5,4 +5,3 @@
|
||||||
name: "{{ mariadb_service_name }}"
|
name: "{{ mariadb_service_name }}"
|
||||||
state: restarted
|
state: restarted
|
||||||
when: mariadb_notify_restart
|
when: mariadb_notify_restart
|
||||||
throttle: 1
|
|
||||||
|
|
|
@ -11,7 +11,8 @@ galaxy_info:
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- bookworm
|
- buster
|
||||||
|
- bullseye
|
||||||
galaxy_tags:
|
galaxy_tags:
|
||||||
- database
|
- database
|
||||||
- packaging
|
- packaging
|
||||||
|
|
|
@ -10,9 +10,6 @@ scenario:
|
||||||
- idempotence
|
- idempotence
|
||||||
- verify
|
- verify
|
||||||
- destroy
|
- destroy
|
||||||
dependency:
|
|
||||||
name: shell
|
|
||||||
command: "${MOLECULE_SCENARIO_DIRECTORY}/../_shared/tools/install-dependencies.sh"
|
|
||||||
driver:
|
driver:
|
||||||
name: docker
|
name: docker
|
||||||
role_name_check: 1
|
role_name_check: 1
|
||||||
|
|
|
@ -2,4 +2,3 @@
|
||||||
|
|
||||||
mariadb_use_galera: true
|
mariadb_use_galera: true
|
||||||
mariadb_galera_members: "{{ groups['galera'] }}"
|
mariadb_galera_members: "{{ groups['galera'] }}"
|
||||||
mariadb_galera_primary_node: "{{ mariadb_galera_members | first }}"
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ -z "${IS_GITHUB_ACTIONS}" ]; then
|
|
||||||
echo "This script is run in GitHub Actions."
|
|
||||||
pip install netaddr
|
|
||||||
fi
|
|
||||||
|
|
||||||
ansible-galaxy collection install -r requirements.yml
|
|
|
@ -1,9 +0,0 @@
|
||||||
---
|
|
||||||
|
|
||||||
- name: Converge
|
|
||||||
hosts: all
|
|
||||||
gather_facts: true
|
|
||||||
tasks:
|
|
||||||
- name: Include role
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: "hanxhx.mysql"
|
|
|
@ -1,55 +0,0 @@
|
||||||
---
|
|
||||||
|
|
||||||
platforms:
|
|
||||||
- name: debian12-galera1
|
|
||||||
image: dokken/debian-12
|
|
||||||
command: /lib/systemd/systemd
|
|
||||||
dockerfile: ../_shared/Dockerfile.j2
|
|
||||||
capabilities:
|
|
||||||
- SYS_ADMIN
|
|
||||||
cgroupns_mode: host
|
|
||||||
volumes:
|
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
|
||||||
privileged: true
|
|
||||||
groups:
|
|
||||||
- galera
|
|
||||||
networks:
|
|
||||||
- name: "00-molecule-d12-galera"
|
|
||||||
ipv4_address: '172.16.51.1'
|
|
||||||
docker_networks:
|
|
||||||
- name: "00-molecule-d12-galera"
|
|
||||||
ipam_config:
|
|
||||||
- subnet: "172.16.51.0/24"
|
|
||||||
gateway: "172.16.51.254"
|
|
||||||
|
|
||||||
- name: debian12-galera2
|
|
||||||
image: dokken/debian-12
|
|
||||||
command: /lib/systemd/systemd
|
|
||||||
dockerfile: ../_shared/Dockerfile.j2
|
|
||||||
capabilities:
|
|
||||||
- SYS_ADMIN
|
|
||||||
cgroupns_mode: host
|
|
||||||
volumes:
|
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
|
||||||
privileged: true
|
|
||||||
groups:
|
|
||||||
- galera
|
|
||||||
networks:
|
|
||||||
- name: "00-molecule-d12-galera"
|
|
||||||
ipv4_address: '172.16.51.2'
|
|
||||||
|
|
||||||
- name: debian12-galera3
|
|
||||||
image: dokken/debian-12
|
|
||||||
command: /lib/systemd/systemd
|
|
||||||
dockerfile: ../_shared/Dockerfile.j2
|
|
||||||
capabilities:
|
|
||||||
- SYS_ADMIN
|
|
||||||
cgroupns_mode: host
|
|
||||||
volumes:
|
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
|
||||||
privileged: true
|
|
||||||
groups:
|
|
||||||
- galera
|
|
||||||
networks:
|
|
||||||
- name: "00-molecule-d12-galera"
|
|
||||||
ipv4_address: '172.16.51.3'
|
|
|
@ -1,31 +0,0 @@
|
||||||
---
|
|
||||||
|
|
||||||
- name: Verify Galera
|
|
||||||
hosts: galera
|
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- name: MYSQL_QUERY | Check if Galera is running
|
|
||||||
community.mysql.mysql_query:
|
|
||||||
query: "SHOW GLOBAL STATUS LIKE 'wsrep_ready'"
|
|
||||||
login_unix_socket: /run/mysqld/mysqld.sock
|
|
||||||
register: wsrep_ready
|
|
||||||
|
|
||||||
- name: ASSERT | Fail if Galera is not running
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- wsrep_ready.query_result.0.0.Value == "ON"
|
|
||||||
fail_msg: "Galera is not running"
|
|
||||||
success_msg: "Galera is running"
|
|
||||||
|
|
||||||
- name: MYSQL_QUERY | Check Galera status
|
|
||||||
community.mysql.mysql_query:
|
|
||||||
query: "SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment'"
|
|
||||||
login_unix_socket: /run/mysqld/mysqld.sock
|
|
||||||
register: wsrep_local_state_comment
|
|
||||||
|
|
||||||
- name: ASSERT | Fail if Galera is not on the right state
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- wsrep_local_state_comment.query_result.0.0.Value == "Synced"
|
|
||||||
fail_msg: "Galera is not expected state ({{ wsrep_local_state_comment.query_result.0.0.Value }})"
|
|
||||||
success_msg: "Galera is in expected state"
|
|
|
@ -24,8 +24,6 @@
|
||||||
target: /tmp/import1.sql
|
target: /tmp/import1.sql
|
||||||
login_unix_socket: "/run/mysqld/mysqld.sock"
|
login_unix_socket: "/run/mysqld/mysqld.sock"
|
||||||
loop: "{{ mariadb_databases }}"
|
loop: "{{ mariadb_databases }}"
|
||||||
tags:
|
|
||||||
- molecule-idempotence-notest
|
|
||||||
|
|
||||||
- name: Converge slave
|
- name: Converge slave
|
||||||
hosts: slave
|
hosts: slave
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: SET_FACT | Prepare mark var
|
- name: SET_FACT | Prepare mark var
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
__mark: "{{ mariadb_datadir }}/.ansible_galera_boostrap"
|
__mark: "{{ mariadb_datadir }}/.ansible_galera_boostrap"
|
||||||
|
|
|
@ -2,20 +2,31 @@
|
||||||
|
|
||||||
- name: APT | Install Galera
|
- name: APT | Install Galera
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: "{{ mariadb_galera_package_name }}"
|
pkg: "{{ mariadb_galera_package_name }}"
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy Galera configuration
|
- name: TEMPLATE | Deploy Galera configuration
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: etc/mysql/mariadb.conf.d/60-galera.cnf.j2
|
src: etc/mysql/mariadb.conf.d/20-galera.cnf.j2
|
||||||
dest: /etc/mysql/mariadb.conf.d/60-galera.cnf
|
dest: /etc/mysql/mariadb.conf.d/20-galera.cnf
|
||||||
mode: 0644
|
mode: 0644
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
notify: Restart mariadb
|
register: galeraconfig
|
||||||
|
|
||||||
- name: INCLUDE | Bootstrap first node
|
- name: INCLUDE | Bootstrap first node
|
||||||
ansible.builtin.import_tasks: 'bootstrap.yml'
|
ansible.builtin.import_tasks: 'bootstrap.yml'
|
||||||
when: inventory_hostname == mariadb_galera_primary_node
|
when: inventory_hostname == mariadb_galera_primary_node
|
||||||
|
|
||||||
- name: META | Flush handlers
|
- name: INCLUDE | Configure other nodes
|
||||||
ansible.builtin.meta: flush_handlers
|
ansible.builtin.import_tasks: 'nodes.yml'
|
||||||
|
when: inventory_hostname != mariadb_galera_primary_node
|
||||||
|
|
||||||
|
- name: SERVICE | Restart MariaDB if needed
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: "{{ mariadb_service_name }}"
|
||||||
|
state: restarted
|
||||||
|
when:
|
||||||
|
((galeraconfig or (p is defined and p.changed)) and
|
||||||
|
(bootstrap_run is not defined)) or
|
||||||
|
((inventory_hostname != mariadb_galera_primary_node) and
|
||||||
|
(mariadb_galera_resetup))
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: COMMAND | GET debian.cnf from primary node
|
||||||
|
ansible.builtin.command: cat /etc/mysql/debian.cnf
|
||||||
|
register: debiancnf
|
||||||
|
delegate_to: '{{ mariadb_galera_primary_node }}'
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: COMMAND | Get current debian.cnf
|
||||||
|
ansible.builtin.command: cat /etc/mysql/debian.cnf
|
||||||
|
register: ondc
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: BLOCK | Compare debian.cnf
|
||||||
|
when: debiancnf.stdout != ondc.stdout
|
||||||
|
block:
|
||||||
|
|
||||||
|
- name: SERVICE | Stop MariaDB
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: "{{ mariadb_service_name }}"
|
||||||
|
state: stopped
|
||||||
|
|
||||||
|
- name: COPY | Paste primary node's debian.cnf
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: "{{ debiancnf.stdout }}"
|
||||||
|
dest: /etc/mysql/debian.cnf
|
||||||
|
mode: 0600
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
register: paste
|
||||||
|
|
||||||
|
- name: SERVICE | Start MariaDB
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: "{{ mariadb_service_name }}"
|
||||||
|
state: started
|
|
@ -36,7 +36,6 @@
|
||||||
- etc/mysql/conf.d/mysqldump.cnf.j2
|
- etc/mysql/conf.d/mysqldump.cnf.j2
|
||||||
- etc/mysql/mariadb.conf.d/10-extra.cnf.j2
|
- etc/mysql/mariadb.conf.d/10-extra.cnf.j2
|
||||||
- etc/mysql/mariadb.conf.d/50-server.cnf.j2
|
- etc/mysql/mariadb.conf.d/50-server.cnf.j2
|
||||||
notify: Restart mariadb
|
|
||||||
|
|
||||||
- name: FILE | Ensure log dir exists
|
- name: FILE | Ensure log dir exists
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
|
@ -46,8 +45,14 @@
|
||||||
owner: mysql
|
owner: mysql
|
||||||
group: mysql
|
group: mysql
|
||||||
|
|
||||||
- name: META | Flush handlers
|
- name: SERVICE | Restart Mariadb now one at a time (prevent bugs)
|
||||||
ansible.builtin.meta: flush_handlers
|
throttle: 1
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: "{{ mariadb_service_name }}"
|
||||||
|
state: restarted
|
||||||
|
when:
|
||||||
|
config.changed and
|
||||||
|
not mariadb_galera_resetup
|
||||||
|
|
||||||
- name: SERVICE | Ensure service is started
|
- name: SERVICE | Ensure service is started
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
# Global
|
# Global
|
||||||
wsrep_on = ON
|
wsrep_on = ON
|
||||||
wsrep_provider = /usr/lib/galera/libgalera_smm.so
|
|
||||||
wsrep_cluster_address = gcomm://{{ mariadb_galera_members | join(",") }}
|
wsrep_cluster_address = gcomm://{{ mariadb_galera_members | join(",") }}
|
||||||
wsrep_sst_method = "{{ mariadb_wsrep_sst_method }}"
|
wsrep_sst_method = "{{ mariadb_wsrep_sst_method }}"
|
||||||
{% if mariadb_wsrep_cluster_name is defined %}
|
{% if mariadb_wsrep_cluster_name is defined %}
|
||||||
|
@ -20,7 +19,7 @@ wsrep_cluster_name = "{{ mariadb_wsrep_cluster_name }}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
# Node Configuration
|
# Node Configuration
|
||||||
wsrep_node_address = "{{ mariadb_wsrep_node_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) }}"
|
||||||
|
|
||||||
# Deps
|
# Deps
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
About tests
|
||||||
|
===========
|
||||||
|
|
||||||
|
IMPORTANT
|
||||||
|
---------
|
||||||
|
|
||||||
|
- DO NOT `vagrant up`! My Vagrantfile provides many VMs...
|
||||||
|
- Each slave communicate to his master.
|
||||||
|
|
||||||
|
Tests
|
||||||
|
-----
|
||||||
|
|
||||||
|
- vagrant up the-master
|
||||||
|
- vagrant up the-slave
|
||||||
|
|
||||||
|
Wait master fully installed before run slave.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
vagrant up vbox-buster-default-master
|
||||||
|
vagrant up vbox-buster-default-slave
|
||||||
|
```
|
|
@ -0,0 +1,6 @@
|
||||||
|
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (51,"vulputate.eu.odio@elitdictumeu.net"),(52,"Sed.eu@erosnec.edu"),(53,"magna@interdum.co.uk"),(54,"ornare.libero.at@Proin.net"),(55,"turpis@aneque.org"),(56,"ut.eros.non@Duisrisusodio.com"),(57,"Pellentesque.ultricies.dignissim@malesuada.edu"),(58,"vel.nisl@mifringilla.net"),(59,"dui@laoreet.com"),(60,"vitae@Suspendissedui.net");
|
||||||
|
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (61,"turpis@Curabituregestasnunc.co.uk"),(62,"arcu@enim.co.uk"),(63,"consectetuer.rhoncus.Nullam@dolordolortempus.co.uk"),(64,"sem@felisadipiscingfringilla.net"),(65,"aliquet.metus.urna@a.net"),(66,"Fusce.fermentum.fermentum@variusNam.com"),(67,"dolor@velnisl.ca"),(68,"et.netus@Duisrisusodio.edu"),(69,"malesuada@purus.edu"),(70,"gravida.sagittis@pulvinararcuet.ca");
|
||||||
|
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (71,"et.eros.Proin@Cras.co.uk"),(72,"eleifend.nunc.risus@metuseu.edu"),(73,"pede.Nunc@Phasellusnulla.net"),(74,"vitae.sodales.at@ipsumdolor.edu"),(75,"nunc.sed.pede@aliquetlobortisnisi.co.uk"),(76,"consectetuer@nonenim.ca"),(77,"ultrices@tinciduntvehicula.co.uk"),(78,"Nullam.enim.Sed@Morbiaccumsan.com"),(79,"auctor@Phasellus.net"),(80,"enim.Etiam@interdum.com");
|
||||||
|
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (81,"sapien.Cras.dolor@consectetuer.com"),(82,"malesuada.fames.ac@feugiattelluslorem.edu"),(83,"risus@vestibulum.co.uk"),(84,"Nunc@Duisgravida.ca"),(85,"ornare.egestas@sitamet.edu"),(86,"Proin.ultrices@senectus.ca"),(87,"ligula@magna.edu"),(88,"orci.tincidunt.adipiscing@sed.com"),(89,"et@venenatis.edu"),(90,"leo.Cras.vehicula@eteuismod.org");
|
||||||
|
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (91,"consequat.auctor.nunc@utsemNulla.net"),(92,"nec.leo@orci.com"),(93,"Nulla@atvelit.edu"),(94,"tempor.augue.ac@eleifend.edu"),(95,"fermentum.risus.at@penatibusetmagnis.edu"),(96,"id.erat.Etiam@porttitortellus.edu"),(97,"amet.metus.Aliquam@mus.co.uk"),(98,"dolor.tempus.non@risus.org"),(99,"vulputate.posuere.vulputate@purus.ca"),(100,"inceptos@pede.edu");
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
localhost
|
|
@ -0,0 +1,122 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
pre_tasks:
|
||||||
|
|
||||||
|
- name: SETUP | Get facts
|
||||||
|
ansible.builtin.setup:
|
||||||
|
register: s
|
||||||
|
|
||||||
|
- name: DEBUG | Show facts
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: s
|
||||||
|
tasks:
|
||||||
|
|
||||||
|
- name: APT | Install some packages
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: "{{ p }}"
|
||||||
|
update_cache: true
|
||||||
|
cache_valid_time: 3600
|
||||||
|
vars:
|
||||||
|
p: ['ca-certificates', 'curl', 'strace', 'rsyslog', 'vim']
|
||||||
|
|
||||||
|
- name: SERVICE | Ensure rsyslog is started
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: rsyslog
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- hosts: master
|
||||||
|
roles:
|
||||||
|
- ../../
|
||||||
|
tasks:
|
||||||
|
|
||||||
|
- name: COPY | Deploy first dump
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: import1.sql
|
||||||
|
dest: /tmp/import1.sql
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
register: c
|
||||||
|
|
||||||
|
- name: MYSQL_DB | Import first dump
|
||||||
|
community.mysql.mysql_db:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: import
|
||||||
|
target: /tmp/import1.sql
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
|
loop: ['testrepl', 'norepl']
|
||||||
|
when: c.changed
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
|
- hosts: slave
|
||||||
|
pre_tasks:
|
||||||
|
|
||||||
|
- name: SHELL | Get master IP
|
||||||
|
ansible.builtin.shell: set -o pipefail && getent hosts {{ ansible_hostname | replace ('slave', 'master') }} | cut -d ' ' -f 1
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
register: ip
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: SET_FACT | Apply some configuration
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
# MariaDB don't read /etc/hosts (from vagrant host plugin)
|
||||||
|
mariadb_replication_host: "{{ ip.stdout }}"
|
||||||
|
# Need this to use vagrant 'delegate_to'
|
||||||
|
mariadb_slave_import_from: "{{ ansible_hostname | replace ('slave', 'master') }}"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- ../../
|
||||||
|
tasks:
|
||||||
|
|
||||||
|
- block:
|
||||||
|
|
||||||
|
- name: COPY | Deploy dump
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: import2.sql
|
||||||
|
dest: /tmp/import2.sql
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||||
|
register: c
|
||||||
|
|
||||||
|
- name: MYSQL_DB | Import another dump
|
||||||
|
community.mysql.mysql_db:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: import
|
||||||
|
target: /tmp/import2.sql
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
|
loop: ['testrepl', 'norepl']
|
||||||
|
when: c.changed
|
||||||
|
|
||||||
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||||
|
|
||||||
|
- name: MYSQL_REPLICATION | Get slave infos
|
||||||
|
community.mysql.mysql_replication:
|
||||||
|
mode: getslave
|
||||||
|
register: slave
|
||||||
|
|
||||||
|
- name: FAIL | if slave threads are not running
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "Slave issue"
|
||||||
|
when: slave.Slave_IO_Running != 'Yes' or slave.Slave_SQL_Running != 'Yes'
|
||||||
|
|
||||||
|
- hosts: galera
|
||||||
|
pre_tasks:
|
||||||
|
|
||||||
|
- name: APT_REPOSITORY | Force galera-3 on Buster + MariaDB from Debian repository (prevent crashes)
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
mariadb_galera_package_name: 'galera-3'
|
||||||
|
when: ansible_distribution_release == 'buster' and mariadb_origin == 'default'
|
||||||
|
|
||||||
|
- name: SET_FACT | Apply some configuration
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
mariadb_galera_primary_node: '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-{{ mariadb_origin }}-galera-1'
|
||||||
|
mariadb_wsrep_node_address: "{{ '127.0.0.1' if is_docker else ansible_eth1.ipv4.address }}"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- ../../
|
Loading…
Reference in New Issue