Compare commits

...

16 Commits

Author SHA1 Message Date
Emilien Mantel d2ec2eaa28 🔧 Prepare galaxy release 2024-08-27 12:08:42 +02:00
Emilien Mantel a936b1b1a0 🔥 Remove lagacy code
- Drop Vagrant support
- Drop TravisCI
- Remove legacy tests
2024-08-27 12:08:21 +02:00
Emilien Mantel 174799ee17 🚀 Manage Galera 2024-08-27 12:08:21 +02:00
Emilien Mantel 6eeb28133e 🐛 Fix idempotence 2024-08-27 12:08:21 +02:00
Emilien Mantel 309cafcd37 📝 Update README 2024-08-27 12:08:21 +02:00
Emilien Mantel 23e385e146 👷 Fix linter 2024-08-27 12:08:21 +02:00
Emilien Mantel 35c871d873 🐛 Fix crash on non upstream calls with bad import sql file 2024-08-27 12:08:21 +02:00
Emilien Mantel 4b35bc06fc 👷 Add Github Action 2024-08-27 12:08:21 +02:00
Emilien Mantel d5ea499a4c 🎨 Cleanup vars 2024-08-27 12:08:21 +02:00
Emilien Mantel de83310be5 🎨 Modernize config files 2024-08-27 12:08:21 +02:00
Emilien Mantel 16c7e750f6 🚀 Upstream management on molecule 2024-08-27 12:08:21 +02:00
Emilien Mantel d9672a9b19 🔨 Add molecule 2024-08-27 12:08:21 +02:00
Emilien Mantel be00c762a6 🐛 Fix ansible mysql calls
due to wokes changes...
2024-08-27 12:08:21 +02:00
Emilien Mantel 5841e55a45 🚨 Fix modernized linter 2024-08-27 12:08:16 +02:00
Emilien Mantel 8a060a84ba Add collection deps 2024-08-27 11:39:14 +02:00
Emilien Mantel a03b256d05 Add ansible libs 2024-08-27 11:38:55 +02:00
58 changed files with 672 additions and 675 deletions

View File

@ -6,5 +6,6 @@ skip_list: []
exclude_paths: exclude_paths:
- venv/ - venv/
- tests/ # TODO: Remove this line when tests are migrated to molecule
- .github/ - .github/
offline: false

49
.github/workflows/ci.yml vendored 100644
View File

@ -0,0 +1,49 @@
---
name: ci
'on':
pull_request:
push:
branches:
- master
jobs:
yaml-lint:
name: YAML Lint
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v4
- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install test dependencies.
run: pip3 install yamllint
- name: Lint code.
run: |
yamllint .
ansible-lint:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v4
- name: Set up Python 3.
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install lib dependencies
run: pip3 install netaddr
- name: Run ansible-lint
uses: ansible/ansible-lint@v24.7.0

17
.github/workflows/galaxy.yml vendored 100644
View File

@ -0,0 +1,17 @@
---
name: Deploy on Ansible Galaxy
'on':
- push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v4
- name: galaxy
uses: robertdebock/galaxy-action@1.2.0
with:
galaxy_api_key: ${{ secrets.galaxy_api_key }}

41
.github/workflows/molecule.yml vendored 100644
View File

@ -0,0 +1,41 @@
---
name: Molecule
'on':
pull_request:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
scenario:
- debian12_galera
- debian12_master_slave
- debian12_upstream
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: "${{ github.repository }}"
- name: Set up Python 3.
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install lib dependencies
run: pip3 install netaddr
- name: Molecule
uses: gofrolist/molecule-action@v2
with:
molecule_options: --base-config molecule/_shared/base.yml
molecule_args: --scenario-name ${{ matrix.scenario }}
env:
ANSIBLE_FORCE_COLOR: '1'

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
.vagrant*
*.swp *.swp
*.retry *.retry
/.idea /.idea

View File

@ -1,57 +0,0 @@
---
env:
global:
- VAGRANT_VERSION='2.2.18'
jobs:
- PLATFORM='docker-buster-default-master' ANSIBLE_VERSION='>=2.11,<2.12'
- PLATFORM='docker-buster-upstream-master' ANSIBLE_VERSION='>=2.11,<2.12'
- PLATFORM='docker-buster-default-galera-1' ANSIBLE_VERSION='>=2.11,<2.12'
- PLATFORM='docker-buster-upstream-galera-1' ANSIBLE_VERSION='>=2.11,<2.12'
- PLATFORM='docker-bullseye-default-master' ANSIBLE_VERSION='>=2.11,<2.12'
- PLATFORM='docker-bullseye-upstream-master' ANSIBLE_VERSION='>=2.11,<2.12'
- PLATFORM='docker-bullseye-default-galera-1' ANSIBLE_VERSION='>=2.11,<2.12'
- PLATFORM='docker-bullseye-upstream-galera-1' ANSIBLE_VERSION='>=2.11,<2.12'
os:
- linux
dist: focal
language: python
python:
- 3.8
services:
- docker
before_install:
- sudo apt-get -q update
- sudo apt-get install -y yamllint
- sudo wget -nv https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb
- sudo dpkg -i vagrant_${VAGRANT_VERSION}_x86_64.deb
- vagrant plugin install vagrant-hostmanager
install:
- sudo pip install "ansible-core$ANSIBLE_VERSION"
- sudo pip install ansible-lint
- ansible-galaxy collection install community.general community.mysql community.crypto ansible.posix
script:
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
- >
VAGRANT_DEFAULT_PROVIDER=docker vagrant provision $PLATFORM
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
- VAGRANT_DEFAULT_PROVIDER=docker vagrant status
- >
yamllint .
&& (echo 'YAML lint test: pass' && exit 0)
|| (echo 'YAML lint test: fail' && exit 1)
- >
ansible-lint -v tests/test.yml
&& (echo 'Ansible lint test: pass' && exit 0)
|| (echo 'Ansible lint test: fail' && exit 1)
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -7,4 +7,3 @@ rules:
ignore: ignore:
- /venv - /venv
- /tests # TODO: Remove this line when tests are migrated to molecule

View File

@ -1,30 +1,28 @@
MariaDB (MySQL) Ansible role for Debian MariaDB (MySQL) Ansible role for Debian
======================================= =======================================
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.mysql-blue.svg)](https://galaxy.ansible.com/HanXHX/mysql) [![Build Status](https://app.travis-ci.com/HanXHX/ansible-mysql.svg?branch=master)](https://app.travis-ci.com/HanXHX/ansible-mysql) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.mysql-blue.svg)](https://galaxy.ansible.com/HanXHX/mysql) ![GitHub Workflow Status (master)](https://img.shields.io/github/actions/workflow/status/hanxhx/ansible-mysql/molecule.yml?branch=master)
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 | Origin | MariaDB versions | | OS | Origin | MariaDB versions |
| --------------- | --------- | ----------------- | |:--------------------:|:----------|:-----------------|
| Debian Buster | Debian | 10.3 | | Debian Bookworm (12) | Debian | 10.11 |
| Debian Buster | Upstream | Up from 10.3 | | Debian Bookworm (12) | Upstream | From 10.11 |
| Debian Bullseye | Debian | 10.5 |
| Debian Bullseye | Upstream | Up from 10.5 | If you need to manage previous Debian versions, please use the [latest managed version](https://github.com/HanXHX/ansible-mysql/releases/tag/2.2.1).
Notes Notes
----- -----
* Galera Cluster is experimental * Galera Cluster is experimental. Feel free to test it and report issues.
* 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
------------ ------------
- Ansible >=2.11 - Ansible - see [meta/main.yml](meta/main.yml)
- Collections: community.general / community.mysql / community.crypto / ansible.posix - Collections: see [requirements.yml](requirements.yml)
Role Variables Role Variables
-------------- --------------
@ -57,7 +55,7 @@ mariadb_users:
host_all: yes host_all: yes
``` ```
Check "priv" syntax in [mysql\_user module documentation](http://docs.ansible.com/mysql_user_module.html) Check "priv" syntax in [mysql\_user module documentation](https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_user_module.html)
### Packaging ### Packaging
@ -72,12 +70,23 @@ Dependencies
None. None.
If you need to dev this role locally with molecule
--------------------------------------------------
Check available scenarios in [molecule](molecule) directory.
With `debian12_master_slave` scenario:
```commandline
molecule -v -c molecule/_shared/base.yml verify -s debian12_master_slave
```
Example Playbook Example Playbook
---------------- ----------------
- hosts: servers - hosts: servers
roles: roles:
- { role: HanXHX.mysql, mariadb_origin: 'upstream' } - { role: hanxhx.mysql, mariadb_origin: 'upstream' }
License License
------- -------

114
Vagrantfile vendored
View File

@ -1,114 +0,0 @@
# -*- 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

View File

@ -35,7 +35,6 @@ mariadb_read_buffer_size: '1M'
mariadb_read_rnd_buffer_size: '2M' mariadb_read_rnd_buffer_size: '2M'
mariadb_myisam_sort_buffer_size: '128M' mariadb_myisam_sort_buffer_size: '128M'
mariadb_thread_cache_size: '256' mariadb_thread_cache_size: '256'
mariadb_query_cache_size: '16M'
# Other settings. # Other settings.
mariadb_wait_timeout: 28800 mariadb_wait_timeout: 28800
@ -69,7 +68,6 @@ mariadb_extra_configuration: {}
# ------------------------------------- # -------------------------------------
mariadb_replication_master: false mariadb_replication_master: false
mariadb_replication_slave: false mariadb_replication_slave: false
# This formula don't work with vagrant! All boxes have same default ip!
mariadb_server_id: "{{ ansible_default_ipv4.address | ipaddr('int') }}" mariadb_server_id: "{{ ansible_default_ipv4.address | ipaddr('int') }}"
mariadb_replication_user: 'repl' mariadb_replication_user: 'repl'
@ -117,16 +115,16 @@ mariadb_users: []
# MariaDB Upstream # MariaDB Upstream
# ------------------------------------- # -------------------------------------
mariadb_upstream_setup_script: 'https://r.mariadb.com/downloads/mariadb_repo_setup' mariadb_upstream_setup_script: 'https://r.mariadb.com/downloads/mariadb_repo_setup'
mariadb_upstream_version: '10.6' mariadb_upstream_version: '11.4'
# ------------------------------------- # -------------------------------------
# Galera # Galera
# ------------------------------------- # -------------------------------------
mariadb_galera_resetup: false mariadb_galera_resetup: false
mariadb_wsrep_node_address: false # Set primary node IP mariadb_wsrep_node_address: '{{ ansible_default_ipv4.address if ansible_default_ipv4 is defined else "127.0.0.1" }}'
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_sst_method: 'rsync'
mariadb_galera_package_name: 'galera-4' mariadb_galera_package_name: 'galera-4'

View File

@ -1,7 +1,8 @@
--- ---
- name: restart mariadb - name: Restart mariadb
ansible.builtin.service: ansible.builtin.service:
name: "{{ mariadb_service_name }}" name: "{{ mariadb_service_name }}"
state: restarted state: restarted
when: mariadb_notify_restart when: mariadb_notify_restart
throttle: 1

View File

@ -5,14 +5,13 @@ galaxy_info:
role_name: mysql role_name: mysql
author: Emilien Mantel author: Emilien Mantel
description: Install and configure MariaDB (and Galera Cluster) on Debian description: Install and configure MariaDB (and Galera Cluster) on Debian
company: company: TripleStack
license: GPLv2 license: GPLv2
min_ansible_version: 2.11 min_ansible_version: '2.17'
platforms: platforms:
- name: Debian - name: Debian
versions: versions:
- buster - bookworm
- bullseye
galaxy_tags: galaxy_tags:
- database - database
- packaging - packaging

View File

@ -0,0 +1,19 @@
# Molecule managed
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}
RUN apt-get update && \
apt-get install -y python3 sudo bash ca-certificates iproute2 python-apt-common \
&& apt-get clean

View File

@ -0,0 +1,39 @@
---
scenario:
test_sequence:
- dependency
- syntax
- create
- prepare
- converge
- idempotence
- verify
- destroy
dependency:
name: shell
command: "${MOLECULE_SCENARIO_DIRECTORY}/../_shared/tools/install-dependencies.sh"
driver:
name: docker
role_name_check: 1
provisioner:
name: ansible
config_options:
defaults:
deprecation_warnings: false
callback_whitelist: timer,profile_tasks
fact_caching: jsonfile
fact_caching_connection: ./cache
forks: 100
connection:
pipelining: true
playbooks:
prepare: ../_shared/prepare.yml
inventory:
group_vars:
all:
is_dev: true
links:
group_vars: ../_shared/inventory/group_vars/
verifier:
name: ansible

View File

@ -9,4 +9,3 @@ INSERT IGNORE INTO `user` (`id`,`email`) VALUES (11,"vitae.dolor@rutrumnon.net")
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (21,"aliquam@atpretium.co.uk"),(22,"cursus@sapienmolestie.edu"),(23,"ornare.Fusce@pede.ca"),(24,"at@estac.co.uk"),(25,"sed@risusodioauctor.ca"),(26,"sit.amet.consectetuer@necorciDonec.com"),(27,"Nulla@infaucibus.co.uk"),(28,"tempus.scelerisque@utlacusNulla.com"),(29,"pellentesque.a@nostraper.com"),(30,"libero.et.tristique@Nunclaoreet.co.uk"); INSERT IGNORE INTO `user` (`id`,`email`) VALUES (21,"aliquam@atpretium.co.uk"),(22,"cursus@sapienmolestie.edu"),(23,"ornare.Fusce@pede.ca"),(24,"at@estac.co.uk"),(25,"sed@risusodioauctor.ca"),(26,"sit.amet.consectetuer@necorciDonec.com"),(27,"Nulla@infaucibus.co.uk"),(28,"tempus.scelerisque@utlacusNulla.com"),(29,"pellentesque.a@nostraper.com"),(30,"libero.et.tristique@Nunclaoreet.co.uk");
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (31,"dolor.sit.amet@Donecelementum.net"),(32,"ornare@massanonante.ca"),(33,"quam.elementum@semper.net"),(34,"Duis.ac.arcu@Integermollis.com"),(35,"magna.Sed.eu@magnaPraesent.co.uk"),(36,"Mauris.eu.turpis@mattis.ca"),(37,"ornare.facilisis.eget@urna.net"),(38,"Sed.diam.lorem@fringilla.co.uk"),(39,"pellentesque.Sed.dictum@Donec.edu"),(40,"faucibus.Morbi@nuncid.com"); INSERT IGNORE INTO `user` (`id`,`email`) VALUES (31,"dolor.sit.amet@Donecelementum.net"),(32,"ornare@massanonante.ca"),(33,"quam.elementum@semper.net"),(34,"Duis.ac.arcu@Integermollis.com"),(35,"magna.Sed.eu@magnaPraesent.co.uk"),(36,"Mauris.eu.turpis@mattis.ca"),(37,"ornare.facilisis.eget@urna.net"),(38,"Sed.diam.lorem@fringilla.co.uk"),(39,"pellentesque.Sed.dictum@Donec.edu"),(40,"faucibus.Morbi@nuncid.com");
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (41,"ullamcorper@at.co.uk"),(42,"nec.ante.blandit@utcursus.edu"),(43,"diam.vel.arcu@egestasFuscealiquet.com"),(44,"ridiculus@musAeneaneget.com"),(45,"ad@turpisvitaepurus.ca"),(46,"ultrices.posuere.cubilia@purusMaecenas.net"),(47,"luctus@libero.org"),(48,"mi@elitNulla.com"),(49,"elementum@ipsumdolorsit.edu"),(50,"orci@Donec.co.uk"); INSERT IGNORE INTO `user` (`id`,`email`) VALUES (41,"ullamcorper@at.co.uk"),(42,"nec.ante.blandit@utcursus.edu"),(43,"diam.vel.arcu@egestasFuscealiquet.com"),(44,"ridiculus@musAeneaneget.com"),(45,"ad@turpisvitaepurus.ca"),(46,"ultrices.posuere.cubilia@purusMaecenas.net"),(47,"luctus@libero.org"),(48,"mi@elitNulla.com"),(49,"elementum@ipsumdolorsit.edu"),(50,"orci@Donec.co.uk");

View File

@ -5,3 +5,5 @@ mariadb_extra_configuration:
innodb_commit_concurrency: 0 innodb_commit_concurrency: 0
mariadb_install_xtrabackup_package: true mariadb_install_xtrabackup_package: true
mariadb_slow_query_log_enabled: true mariadb_slow_query_log_enabled: true
mariadb_debug_role: true
mariadb_innodb_buffer_pool_size: 128M

View File

@ -0,0 +1,5 @@
---
mariadb_use_galera: true
mariadb_galera_members: "{{ groups['galera'] }}"
mariadb_galera_primary_node: "{{ mariadb_galera_members | first }}"

View File

@ -15,6 +15,5 @@ mariadb_users:
host: '%' host: '%'
mariadb_replication_master: true mariadb_replication_master: true
mariadb_replication_slave: false mariadb_replication_slave: false
mariadb_server_id: 1
# vim: set ft=yaml : # vim: set ft=yaml :

View File

@ -4,7 +4,8 @@ mariadb_replication_master: false
mariadb_replication_slave: true mariadb_replication_slave: true
mariadb_replication_user: 'replication' mariadb_replication_user: 'replication'
mariadb_replication_password: '1a2b3c' mariadb_replication_password: '1a2b3c'
mariadb_server_id: 2
mariadb_slave_ignore_db: ['norepl'] mariadb_slave_ignore_db: ['norepl']
mariadb_slave_import_from: "{{ groups['master'][0] }}"
mariadb_replication_host: "{{ groups['master'][0] }}"
# vim: set ft=yaml : # vim: set ft=yaml :

View File

@ -0,0 +1,3 @@
---
mariadb_origin: 'upstream'

View File

@ -0,0 +1,21 @@
---
- name: Prepare hosts
hosts: all
gather_facts: false
tasks:
- name: APT | Install some packages
ansible.builtin.apt:
name: "{{ p }}"
update_cache: true
cache_valid_time: 3600
vars:
p: ['ca-certificates', 'curl', 'rsync', 'rsyslog', 'ssh', 'strace', 'vim']
- name: SERVICE | Ensure daemon are started
ansible.builtin.service:
name: "{{ item }}"
state: started
loop:
- rsyslog
- ssh

View File

@ -0,0 +1,8 @@
#!/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

View File

@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
gather_facts: true
tasks:
- name: Include role
ansible.builtin.include_role:
name: "hanxhx.mysql"

View File

@ -0,0 +1,55 @@
---
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'

View File

@ -0,0 +1,31 @@
---
- 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"

View File

@ -0,0 +1,36 @@
---
# Note: master must be converged first
- name: Converge master
hosts: master
gather_facts: true
tasks:
- name: Include role
ansible.builtin.include_role:
name: "hanxhx.mysql"
- name: COPY | Deploy first dump
ansible.builtin.copy:
src: ../_shared/files/import1.sql
dest: /tmp/import1.sql
mode: 0644
owner: root
group: root
- name: MYSQL_DB | Import first dump
community.mysql.mysql_db:
name: "{{ item }}"
state: import
target: /tmp/import1.sql
login_unix_socket: "/run/mysqld/mysqld.sock"
loop: "{{ mariadb_databases }}"
tags:
- molecule-idempotence-notest
- name: Converge slave
hosts: slave
gather_facts: true
tasks:
- name: Include role
ansible.builtin.include_role:
name: "hanxhx.mysql"

View File

@ -0,0 +1,46 @@
---
platforms:
- name: debian12-master1
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
networks:
- name: "00-molecule-d12-ms"
ipv4_address: '172.16.50.1'
docker_networks:
- name: "00-molecule-d12-ms"
ipam_config:
- subnet: "172.16.50.0/24"
gateway: "172.16.50.254"
groups:
- master
- name: debian12-slave1
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
networks:
- name: "00-molecule-d12-ms"
ipv4_address: '172.16.50.2'
groups:
- slave
provisioner:
inventory:
host_vars: ~
group_vars:
master: ~
slave: ~

View File

@ -0,0 +1,32 @@
---
- name: Verify slave
hosts: slave
gather_facts: false
tasks:
- name: MYSQL_REPLICATION | Get slave infos
community.mysql.mysql_replication:
mode: getreplica
register: slave
- name: ASSERT | If slave threads are not running
ansible.builtin.assert:
that:
- slave.Slave_IO_Running == 'Yes'
- slave.Slave_SQL_Running == 'Yes'
fail_msg: "Slave issue, please check"
success_msg: "Slave is running"
- name: Check replication data
community.mysql.mysql_query:
login_db: testrepl
query: 'SELECT COUNT(*) AS c FROM user'
login_unix_socket: /run/mysqld/mysqld.sock
register: result
- name: ASSERT | Check replication data
ansible.builtin.assert:
that:
- result.query_result.0.0.c == 50
fail_msg: "Replication data is not correct"
success_msg: "Replication data is correct"

View File

@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
gather_facts: true
tasks:
- name: Include role
ansible.builtin.include_role:
name: "hanxhx.mysql"

View File

@ -0,0 +1,15 @@
---
platforms:
- name: debian12-upstream1
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:
- upstream

View File

@ -0,0 +1,11 @@
---
- name: Verify slave
hosts: all
gather_facts: false
tasks:
- name: COMMAND | Check if mariadb is running # noqa: command-instead-of-module
ansible.builtin.command: "systemctl is-active mariadb"
register: mariadb_is_running
changed_when: false
failed_when: mariadb_is_running.rc != 0

52
requirements.txt 100644
View File

@ -0,0 +1,52 @@
ansible==10.3.0
ansible-compat==24.8.0
ansible-core==2.17.3
ansible-lint==24.7.0
attrs==24.2.0
black==24.8.0
bracex==2.5
certifi==2024.7.4
cffi==1.17.0
charset-normalizer==3.3.2
click==8.1.7
click-help-colors==0.9.4
cryptography==43.0.0
distro==1.9.0
docker==6.1.3
enrich==1.2.7
filelock==3.15.4
idna==3.8
importlib_metadata==8.4.0
Jinja2==3.1.4
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
molecule==24.8.0
molecule-plugins==23.5.3
mypy-extensions==1.0.0
netaddr==1.3.0
packaging==24.1
pathspec==0.12.1
platformdirs==4.2.2
pluggy==1.5.0
pycparser==2.22
Pygments==2.18.0
PyYAML==6.0.2
referencing==0.35.1
requests==2.31.0
resolvelib==1.0.1
rich==13.7.1
rpds-py==0.20.0
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
selinux==0.3.0
subprocess-tee==0.4.2
tomli==2.0.1
typing_extensions==4.12.2
urllib3==2.2.2
wcmatch==9.0
websocket-client==1.8.0
yamllint==1.35.1
zipp==3.20.0

8
requirements.yml 100644
View File

@ -0,0 +1,8 @@
---
collections:
- ansible.posix
- ansible.netcommon
- community.crypto
- community.general
- community.mysql

View File

@ -1,4 +1,5 @@
--- ---
- 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"
@ -8,7 +9,9 @@
path: "{{ __mark }}" path: "{{ __mark }}"
register: s register: s
- block: - name: COMMAND | Setup galera cluster
when: not s.stat.exists or mariadb_galera_resetup
block:
- name: SET_FACT | We must NOT restart after bootstrap! - name: SET_FACT | We must NOT restart after bootstrap!
ansible.builtin.set_fact: ansible.builtin.set_fact:
mariadb_notify_restart: false mariadb_notify_restart: false
@ -21,6 +24,7 @@
- name: COMMAND | Bootstrap first node (systemd) - name: COMMAND | Bootstrap first node (systemd)
ansible.builtin.command: galera_new_cluster ansible.builtin.command: galera_new_cluster
when: ansible_service_mgr == 'systemd' when: ansible_service_mgr == 'systemd'
changed_when: true
- name: SERVICE | Bootstrap first node (clean init) - name: SERVICE | Bootstrap first node (clean init)
ansible.builtin.service: ansible.builtin.service:
@ -30,8 +34,6 @@
register: bootstrap_run register: bootstrap_run
when: ansible_service_mgr != 'systemd' when: ansible_service_mgr != 'systemd'
when: not s.stat.exists or mariadb_galera_resetup
- name: COMMAND | Create Bootstrap mark - name: COMMAND | Create Bootstrap mark
ansible.builtin.command: "touch {{ __mark }}" ansible.builtin.command: "touch {{ __mark }}"
args: args:

View File

@ -2,31 +2,20 @@
- name: APT | Install Galera - name: APT | Install Galera
ansible.builtin.apt: ansible.builtin.apt:
pkg: "{{ mariadb_galera_package_name }}" name: "{{ 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/20-galera.cnf.j2 src: etc/mysql/mariadb.conf.d/60-galera.cnf.j2
dest: /etc/mysql/mariadb.conf.d/20-galera.cnf dest: /etc/mysql/mariadb.conf.d/60-galera.cnf
mode: 0644 mode: 0644
owner: root owner: root
group: root group: root
register: galeraconfig notify: Restart mariadb
- 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: INCLUDE | Configure other nodes - name: META | Flush handlers
ansible.builtin.import_tasks: 'nodes.yml' ansible.builtin.meta: flush_handlers
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))

View File

@ -1,35 +0,0 @@
---
- 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
- 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
when: debiancnf.stdout != ondc.stdout

View File

@ -4,13 +4,15 @@
ansible.builtin.apt: ansible.builtin.apt:
name: gpg name: gpg
- name: COMMAND | Check indempotent - name: COMMAND | Check expected mariadb version
ansible.builtin.command: 'grep -q "{{ mariadb_upstream_version }}" /etc/apt/sources.list.d/mariadb.list' ansible.builtin.command: 'grep -q "{{ mariadb_upstream_version }}" /etc/apt/sources.list.d/mariadb.list'
register: check_idempotent register: check_version
failed_when: false failed_when: false
changed_when: false changed_when: false
- block: - name: APT | Add MariaDB upstream repository
when: check_version.rc > 0
block:
- name: GET_URL | Download MariaDB setup script - name: GET_URL | Download MariaDB setup script
ansible.builtin.get_url: ansible.builtin.get_url:
@ -28,12 +30,3 @@
ansible.builtin.file: ansible.builtin.file:
path: '/tmp/mariadb_repo_setup' path: '/tmp/mariadb_repo_setup'
state: absent state: absent
when: check_idempotent.rc > 0
- name: SHELL | Remove useless old files
ansible.builtin.shell: 'rm -f /etc/apt/sources.list.d/mariadb.list.old_*'
args:
removes: /etc/apt/sources.list.d/mariadb.list.old_1
tags:
- skip_ansible_lint

View File

@ -19,6 +19,11 @@
- name: INCLUDE | Install - name: INCLUDE | Install
ansible.builtin.import_tasks: install/main.yml ansible.builtin.import_tasks: install/main.yml
- name: SHELL | Get current mariadb version # noqa: risky-shell-pipe
ansible.builtin.shell: dpkg -l mariadb-common | awk '/^ii/ { print $3 }' | sed -r 's/^1://g; s/^([[:digit:]]+\.[[:digit:]]+).+$/\1/g'
register: __mariadb_version
changed_when: false
- name: TEMPLATE | Deploy config files - name: TEMPLATE | Deploy config files
ansible.builtin.template: ansible.builtin.template:
src: "{{ item }}" src: "{{ item }}"
@ -28,21 +33,21 @@
group: root group: root
register: config register: config
loop: loop:
- etc/mysql/my.cnf
- 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-client.cnf.j2
- etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf.j2
- etc/mysql/mariadb.conf.d/50-server.cnf.j2 - etc/mysql/mariadb.conf.d/50-server.cnf.j2
notify: Restart mariadb
- name: SERVICE | Restart Mariadb now one at a time (prevent bugs) - name: FILE | Ensure log dir exists
throttle: 1 ansible.builtin.file:
ansible.builtin.service: path: "{{ mariadb_slow_query_log_file | dirname }}"
name: "{{ mariadb_service_name }}" state: directory
state: restarted mode: 0755
when: owner: mysql
config.changed and group: mysql
not mariadb_galera_resetup
- name: META | Flush handlers
ansible.builtin.meta: flush_handlers
- name: SERVICE | Ensure service is started - name: SERVICE | Ensure service is started
ansible.builtin.service: ansible.builtin.service:

View File

@ -7,4 +7,4 @@
mode: 0644 mode: 0644
owner: root owner: root
group: root group: root
notify: restart mariadb notify: Restart mariadb

View File

@ -14,26 +14,26 @@
mode: 0644 mode: 0644
owner: root owner: root
group: root group: root
notify: restart mariadb notify: Restart mariadb
- name: MYSQL_REPLICATION | Get slave status - name: MYSQL_REPLICATION | Get slave status
community.mysql.mysql_replication: community.mysql.mysql_replication:
mode: getslave mode: getreplica
login_unix_socket: "{{ mariadb_socket }}" login_unix_socket: "{{ mariadb_socket }}"
ignore_errors: true ignore_errors: true
register: slave_status register: slave_status
- name: INCLUDE | Import data - name: INCLUDE | Import data
ansible.builtin.import_tasks: slave/import_data.yml ansible.builtin.import_tasks: slave/import_data.yml
when: (slave_status.failed or not slave_status.Is_Slave) and mariadb_slave_import_data when: (slave_status.failed or not slave_status.Is_Replica) and mariadb_slave_import_data
- name: Configure GTID Recplication - name: Configure GTID Replication
ansible.builtin.import_tasks: slave/gtid.yml ansible.builtin.import_tasks: slave/gtid.yml
when: slave_status.failed or not slave_status.Is_Slave or mariadb_slave_force_setup when: slave_status.failed or not slave_status.Is_Replica or mariadb_slave_force_setup
- name: MYSQL_REPLICATION | Get slave status - name: MYSQL_REPLICATION | Get slave status
community.mysql.mysql_replication: community.mysql.mysql_replication:
mode: getslave mode: getreplica
login_unix_socket: "{{ mariadb_socket }}" login_unix_socket: "{{ mariadb_socket }}"
ignore_errors: true ignore_errors: true
register: slave_status register: slave_status

View File

@ -2,12 +2,12 @@
- name: MYSQL_REPLICATION | Stop slave - name: MYSQL_REPLICATION | Stop slave
community.mysql.mysql_replication: community.mysql.mysql_replication:
mode: stopslave mode: stopreplica
login_unix_socket: "{{ mariadb_socket }}" login_unix_socket: "{{ mariadb_socket }}"
- name: MYSQL_REPLICATION | Configure master host - name: MYSQL_REPLICATION | Configure master host
community.mysql.mysql_replication: community.mysql.mysql_replication:
mode: changemaster mode: changeprimary
master_host: "{{ mariadb_replication_host }}" master_host: "{{ mariadb_replication_host }}"
master_port: "{{ mariadb_replication_port }}" master_port: "{{ mariadb_replication_port }}"
master_user: "{{ mariadb_replication_user }}" master_user: "{{ mariadb_replication_user }}"
@ -22,5 +22,5 @@
- name: MYSQL_REPLICATION | Start slave - name: MYSQL_REPLICATION | Start slave
community.mysql.mysql_replication: community.mysql.mysql_replication:
mode: startslave mode: startreplica
login_unix_socket: "{{ mariadb_socket }}" login_unix_socket: "{{ mariadb_socket }}"

View File

@ -7,11 +7,13 @@
mode: 0700 mode: 0700
- name: OPENSSH_KEYPAIR | Create SSH key - name: OPENSSH_KEYPAIR | Create SSH key
openssh_keypair: community.crypto.openssh_keypair:
path: "{{ ansible_env.HOME }}/.ssh/id_rsa" path: "{{ ansible_env.HOME }}/.ssh/id_rsa"
register: gen_ssh register: gen_ssh
- block: - name: BLOCK | Prepare backup
delegate_to: "{{ mariadb_slave_import_from }}"
block:
- name: AUTHORIZED_KEY | Auth slave to backup host - name: AUTHORIZED_KEY | Auth slave to backup host
ansible.posix.authorized_key: ansible.posix.authorized_key:
@ -33,14 +35,12 @@
creates: "{{ mariadb_backup_dir }}/xtrabackup_info" creates: "{{ mariadb_backup_dir }}/xtrabackup_info"
register: backup register: backup
- name: COMMAND | Dump - name: COMMAND | Dump # noqa: no-handler
ansible.builtin.command: "mariabackup --prepare --target-dir={{ mariadb_backup_dir }}" ansible.builtin.command: "mariabackup --prepare --target-dir={{ mariadb_backup_dir }}"
when: backup.changed when: backup.changed
register: prep register: prep
changed_when: "'This target seems to be not prepared yet' in prep.stderr" changed_when: "'This target seems to be not prepared yet' in prep.stderr"
delegate_to: "{{ mariadb_slave_import_from }}"
- name: MYSQL_VARIABLES | Get datadir - name: MYSQL_VARIABLES | Get datadir
community.mysql.mysql_variables: community.mysql.mysql_variables:
variable: datadir variable: datadir
@ -56,8 +56,8 @@
name: "{{ mariadb_service_name }}" name: "{{ mariadb_service_name }}"
state: stopped state: stopped
- name: COMMAND | Sync backup to slave - TODO remove vagrant as static user (see why mariadb_backup_user is not working) - name: COMMAND | Sync backup to slave
ansible.builtin.command: "sudo -E rsync --rsync-path='sudo rsync' -a -e 'ssh -o StrictHostKeyChecking=no' {{ mariadb_backup_user }}@{{ mariadb_slave_import_from }}:{{ mariadb_backup_dir }}/ {{ mariadb_datadir }}/" ansible.builtin.command: "sudo -E rsync --rsync-path='sudo rsync' --delete -a -e 'ssh -o StrictHostKeyChecking=no' {{ mariadb_backup_user }}@{{ mariadb_slave_import_from }}:{{ mariadb_backup_dir }}/ {{ mariadb_datadir }}/"
become: false become: false
tags: tags:
- skip_ansible_lint - skip_ansible_lint
@ -71,12 +71,6 @@
group: mysql group: mysql
recurse: true recurse: true
- name: SHELL | Remove InnoDB redo logs
ansible.builtin.shell: "rm -f {{ mariadb_datadir }}/ib_logfile*"
args:
removes: "{{ mariadb_datadir }}/ib_logfile0"
warn: false
- name: SERVICE | Start MariaDB - name: SERVICE | Start MariaDB
ansible.builtin.service: ansible.builtin.service:
name: "{{ mariadb_service_name }}" name: "{{ mariadb_service_name }}"

View File

@ -1,29 +0,0 @@
---
- name: MYSQL_REPLICATION | Stop slave
mysql_replication:
mode: stopslave
login_unix_socket: "{{ mariadb_socket }}"
- name: MYSQL_REPLICATION | Configure master host
mysql_replication:
mode: changemaster
master_host: "{{ mariadb_replication_host }}"
master_port: "{{ mariadb_replication_port }}"
master_user: "{{ mariadb_replication_user }}"
master_password: "{{ mariadb_replication_password }}"
login_unix_socket: "{{ mariadb_socket }}"
no_log: "{{ not mariadb_debug_role }}"
- name: MYSQL_REPLICATION | Change master
mysql_replication:
mode: changemaster
master_log_file: "{{ mariadb_master_log_file }}"
master_log_pos: "{{ mariadb_master_log_pos }}"
login_unix_socket: "{{ mariadb_socket }}"
when: mariadb_master_log_file is defined and mariadb_master_log_pos is defined
- name: MYSQL_REPLICATION | Start slave
mysql_replication:
mode: startslave
login_unix_socket: "{{ mariadb_socket }}"

View File

@ -1,7 +1,7 @@
--- ---
- name: MYSQL_USER | Remove all anonymous users - name: MYSQL_USER | Remove all anonymous users
mysql_user: community.mysql.mysql_user:
name: '' name: ''
host: "{{ item }}" host: "{{ item }}"
state: absent state: absent
@ -13,7 +13,7 @@
- localhost - localhost
- name: MYSQL_DB | Remove the test database - name: MYSQL_DB | Remove the test database
mysql_db: community.mysql.mysql_db:
name: test name: test
state: absent state: absent
login_unix_socket: "{{ mariadb_socket }}" login_unix_socket: "{{ mariadb_socket }}"

View File

@ -1,3 +1,7 @@
# -------------------------------------------
# {{ ansible_managed }}
# -------------------------------------------
[mysqldump] [mysqldump]
quick quick
quote-names quote-names

View File

@ -1,31 +0,0 @@
#
# {{ ansible_managed }}
#
[mysqld]
# --------------------
# Galera config
# --------------------
# Global
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://{{ mariadb_galera_members | join(",") }}
wsrep_sst_method="{{ mariadb_wsrep_stt_method }}"
{% if mariadb_wsrep_cluster_name is defined %}
wsrep_cluster_name="{{ mariadb_wsrep_cluster_name }}"
{% endif %}
# Node Configuration
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) }}"
# --------------------
# Deps
# --------------------
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_doublewrite=1

View File

@ -1,6 +1,6 @@
# # -------------------------------------------
# {{ ansible_managed }} # {{ ansible_managed }}
# # -------------------------------------------
# Replication master # Replication master

View File

@ -1,8 +1,7 @@
# # -------------------------------------------
# {{ ansible_managed }} # {{ ansible_managed }}
# # -------------------------------------------
#
# Replication slave # Replication slave
[mysqld] [mysqld]

View File

@ -1,29 +0,0 @@
#
# {{ ansible_managed }}
#
#
# This group is read by the client library
# Use it for options that affect all clients, but not the server
#
[client]
# Default is Latin1, if you need UTF-8 set this (also in server section)
default-character-set = utf8mb4
# socket location
socket = {{ mariadb_socket }}
# Example of client certificate usage
# ssl-cert=/etc/mysql/client-cert.pem
# ssl-key=/etc/mysql/client-key.pem
#
# Allow only TLS encrypted connections
# ssl-verify-server-cert=on
# This group is *never* read by mysql client library, though this
# /etc/mysql/mariadb.cnf.d/client.cnf file is not read by Oracle MySQL
# client anyway.
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]

View File

@ -1,34 +0,0 @@
#
# {{ ansible_managed }}
#
# NOTE: This file is read only by the traditional SysV init script, not systemd.
# MariaDB systemd does _not_ utilize mysqld_safe nor read this file.
#
# For similar behaviour, systemd users should create the following file:
# /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
#
# To achieve the same result as the default 50-mysqld_safe.cnf, please create
# /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
# with the following contents:
#
# [Service]
# User=mysql
# StandardOutput=syslog
# StandardError=syslog
# SyslogFacility=daemon
# SyslogLevel=err
# SyslogIdentifier=mysqld
#
# For more information, please read https://mariadb.com/kb/en/mariadb/systemd/
#
[mysqld_safe]
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# especially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
socket = {{ mariadb_socket }}
nice = 0
skip_log_error
syslog

View File

@ -1,18 +1,16 @@
# # -------------------------------------------
# {{ ansible_managed }} # {{ ansible_managed }}
# # -------------------------------------------
# #
# These groups are read by MariaDB server. # These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see # Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql
# this is read by the standalone daemon and embedded servers # this is read by the standalone daemon and embedded servers
[server] [server]
# this is only for the mysqld standalone daemon # this is only for the mariadbd daemon
[mysqld] [mariadbd]
# #
# * Basic Settings # * Basic Settings
@ -25,7 +23,10 @@ basedir = /usr
datadir = {{ mariadb_datadir }} datadir = {{ mariadb_datadir }}
tmpdir = /tmp tmpdir = /tmp
lc-messages-dir = /usr/share/mysql lc-messages-dir = /usr/share/mysql
#skip-external-locking
# Broken reverse DNS slows down connections considerably and name resolve is
# safe to skip if there are no "host by domain name" access grants
#skip-name-resolve
# Instead of skip-networking the default is now to listen only on # Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure. # localhost which is more compatible and is not less secure.
@ -34,6 +35,7 @@ bind-address = {{ mariadb_bind_address }}
# #
# * Fine Tuning # * Fine Tuning
# #
key_buffer_size = {{ mariadb_key_buffer_size }} key_buffer_size = {{ mariadb_key_buffer_size }}
max_allowed_packet = {{ mariadb_max_allowed_packet }} max_allowed_packet = {{ mariadb_max_allowed_packet }}
#thread_stack = 192K #thread_stack = 192K
@ -51,19 +53,22 @@ read_buffer_size = {{ mariadb_read_buffer_size }}
read_rnd_buffer_size = {{ mariadb_read_rnd_buffer_size }} read_rnd_buffer_size = {{ mariadb_read_rnd_buffer_size }}
myisam_sort_buffer_size = {{ mariadb_myisam_sort_buffer_size }} myisam_sort_buffer_size = {{ mariadb_myisam_sort_buffer_size }}
#
# * Query Cache Configuration
#
query_cache_size = {{ mariadb_query_cache_size }}
# #
# * Logging and Replication # * Logging and Replication
# #
# Note: The configured log file or its directory need to be created
# and be writable by the mysql user, e.g.:
# $ sudo mkdir -m 2750 /var/log/mysql
# $ sudo chown mysql /var/log/mysql
# Both location gets rotated by the cronjob. # Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer. # Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime! # Recommend only changing this at runtime for short testing periods if needed!
#general_log_file = /var/log/mysql/mysql.log #general_log_file = /var/log/mysql/mysql.log
#general_log = 1 #general_log = 1
# #
# Error log - should be very few entries. # Error log - should be very few entries.
# #
@ -71,92 +76,66 @@ query_cache_size = {{ mariadb_query_cache_size }}
syslog syslog
syslog-tag = {{ mariadb_syslog_tag }} syslog-tag = {{ mariadb_syslog_tag }}
{% else %} {% else %}
log-error = {{ mariadb_log_error }} log_error = {{ mariadb_log_error }}
{% endif %} {% endif %}
# #
# Enable the slow query log to see queries with especially long duration # Enable the slow query log to see queries with especially long duration
#slow_query_log_file = /var/log/mysql/mariadb-slow.log
#long_query_time = 10
#log_slow_rate_limit = 1000
#log_slow_verbosity = query_plan
#log-queries-not-using-indexes #log-queries-not-using-indexes
{% if mariadb_slow_query_log_enabled %} {% if mariadb_slow_query_log_enabled %}
slow_query_log_file = {{ mariadb_slow_query_log_file }} slow_query_log_file = {{ mariadb_slow_query_log_file }}
long_query_time = {{ mariadb_slow_query_time }} long_query_time = {{ mariadb_slow_query_time }}
slow_query_log = 1 slow_query_log = 1
{% else %}
#slow_query_log_file = /var/log/mysql/mariadb-slow.log
#long_query_time = 10
#log_slow_rate_limit = 1000
#log_slow_verbosity = query_plan
{% endif %} {% endif %}
# #
# The following can be used as easy to replay backup logs or for replication. # * SSL/TLS
# note: if you are setting up a replication slave, see README.Debian about #
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
#expire_logs_days = 10
#max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = exclude_database_name
# # For documentation, please read
# * Security Features # https://mariadb.com/kb/en/securing-connections-for-client-and-server/
#
# Read the manual, too, if you want chroot!
#chroot = /var/lib/mysql/
#
# For generating SSL certificates you can use for example the GUI tool "tinyca".
#
#ssl-ca = /etc/mysql/cacert.pem #ssl-ca = /etc/mysql/cacert.pem
#ssl-cert = /etc/mysql/server-cert.pem #ssl-cert = /etc/mysql/server-cert.pem
#ssl-key = /etc/mysql/server-key.pem #ssl-key = /etc/mysql/server-key.pem
# #require-secure-transport = on
# Accept only connections using the latest and most secure TLS protocol version.
# ..when MariaDB is compiled with OpenSSL:
#ssl-cipher = TLSv1.2
# ..when MariaDB is compiled with YaSSL (default in Debian):
#ssl = on
# #
# * Character sets # * Character sets
# #
# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
# MariaDB default is Latin1, but in Debian we rather default to the full
# utf8 4-byte character set. See also client.cnf # utf8 4-byte character set. See also client.cnf
#
character-set-server = utf8mb4 character-set-server = utf8mb4
collation-server = utf8mb4_general_ci collation-server = utf8mb4_general_ci
# #
# * InnoDB # * InnoDB
# #
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many! # Read the manual for more InnoDB related options. There are many!
innodb_file_per_table = 1 # Most important is to give InnoDB 80 % of the system RAM for buffer use:
# https://mariadb.com/kb/en/innodb-system-variables/#innodb_buffer_pool_size
innodb_buffer_pool_size = {{ mariadb_innodb_buffer_pool_size }} innodb_buffer_pool_size = {{ mariadb_innodb_buffer_pool_size }}
innodb_log_buffer_size = {{ mariadb_innodb_log_buffer_size }} innodb_log_buffer_size = {{ mariadb_innodb_log_buffer_size }}
innodb_flush_log_at_trx_commit = {{ mariadb_innodb_flush_log_at_trx_commit }} innodb_flush_log_at_trx_commit = {{ mariadb_innodb_flush_log_at_trx_commit }}
innodb_lock_wait_timeout = {{ mariadb_innodb_lock_wait_timeout }} innodb_lock_wait_timeout = {{ mariadb_innodb_lock_wait_timeout }}
innodb_log_file_size = {{ mariadb_innodb_log_file_size }} innodb_log_file_size = {{ mariadb_innodb_log_file_size }}
#
# * Unix socket authentication plugin is built-in since 10.0.22-6
#
# Needed so the root database user can authenticate without a password but
# only when running as the unix root user.
#
# Also available for other users if required.
# See https://mariadb.com/kb/en/unix_socket-authentication-plugin/
# this is only for embedded server # this is only for embedded server
[embedded] [embedded]
# This group is only read by MariaDB servers, not by MySQL. # This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB, # If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here # you can put MariaDB-only options here
[mariadb] [mariadbd]
# This group is only read by MariaDB-10.3 servers. # This group is only read by MariaDB-{{ __mariadb_version.stdout }} servers.
# If you use the same .cnf file for MariaDB of different versions, # If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand # use this group for options that older servers don't understand
[mariadb-10.3] [mariadb-{{ __mariadb_version.stdout }}]

View File

@ -0,0 +1,30 @@
# -------------------------------------------
# {{ ansible_managed }}
# -------------------------------------------
#
# * Galera-related settings
#
# See the examples of server wsrep.cnf files in /usr/share/mariadb
# and read more at https://mariadb.com/kb/en/galera-cluster/
[galera]
# Global
wsrep_on = ON
wsrep_provider = /usr/lib/galera/libgalera_smm.so
wsrep_cluster_address = gcomm://{{ mariadb_galera_members | join(",") }}
wsrep_sst_method = "{{ mariadb_wsrep_sst_method }}"
{% if mariadb_wsrep_cluster_name is defined %}
wsrep_cluster_name = "{{ mariadb_wsrep_cluster_name }}"
{% endif %}
# Node Configuration
wsrep_node_address = "{{ mariadb_wsrep_node_address }}"
wsrep_node_name = "{{ mariadb_wsrep_node_name | default(ansible_fqdn) }}"
# Deps
binlog_format = ROW
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
innodb_doublewrite = 1

View File

@ -1,23 +0,0 @@
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

View File

@ -1,23 +0,0 @@
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
```

View File

@ -1,7 +0,0 @@
---
mariadb_use_galera: true
mariadb_galera_members:
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-{{ mariadb_origin }}-galera-1'
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-{{ mariadb_origin }}-galera-2'
- '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-{{ mariadb_origin }}-galera-3'

View File

@ -1,6 +0,0 @@
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");

View File

@ -1 +0,0 @@
localhost

View File

@ -1,122 +0,0 @@
---
- 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:
- ../../