Initial commit

This commit is contained in:
Sven Velt 2020-12-01 22:05:58 +01:00
commit 0c855bf1c7
6 changed files with 309 additions and 0 deletions

155
.gitignore vendored Normal file
View file

@ -0,0 +1,155 @@
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# ---> Vim
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
# ---> Ansible
*.retry

38
README.md Normal file
View file

@ -0,0 +1,38 @@
Role Name
=========
Setup MariaDB galera cluster - JUST SETUP, do NOT run again!
Requirements
------------
At least two MariaDB-Servers
Role Variables
--------------
- None
Dependencies
------------
- None
Example Playbook
----------------
- hosts: db-servers
roles:
- { role: mariadb-galera }
License
-------
GPL-2.0-or-later
Author Information
------------------
Sven Velt <sven-ansiblerole@velt.biz>
https://git.velt.biz/velt.biz/

8
defaults/main.yml Normal file
View file

@ -0,0 +1,8 @@
---
db_packages:
- mariadb-server
- python3-mysqldb
- rsync
db_servicename: mysql

23
meta/main.yml Normal file
View file

@ -0,0 +1,23 @@
galaxy_info:
author: Sven Velt
description: Setup MariaDB galera cluster
company: velt.biz
issue_tracker_url: https://git.velt.biz/Ansible/mariadb-galera/issues/
license: GPL-2.0-or-later
min_ansible_version: 2.9
platforms:
- name: Ubuntu
versions:
- focal
galaxy_tags:
- cluster
- database
- db
- galera
- mariadb

64
tasks/main.yml Normal file
View file

@ -0,0 +1,64 @@
---
- name: Install software
package:
name: "{{ item }}"
state: present
with_items: "{{ db_packages }}"
- name: "Quick-Fix MariaDB/systemd problems"
lineinfile:
path: /usr/lib/systemd/system/mariadb.service
regexp: "^SendSIGKILL=no"
line: "SendSIGKILL=yes"
backup: yes
register: db_systemd_fix
when: ansible_virtualization_type == "lxc"
- name: Reload systemd daemon
command: /bin/systemctl daemon-reload
when: db_systemd_fix is changed
- name: Get MariaDB settings
mysql_info:
filter: settings
register: db_settings
- name: "Config: Listen on all ip addresses"
lineinfile:
path: /etc/mysql/mariadb.conf.d/50-server.cnf
regexp: "^ *#* *bind-address"
line: "bind-address = 0.0.0.0"
backup: yes
- name: Template galera.cnf
template:
src: galera.cnf.j2
dest: /etc/mysql/conf.d/galera.cnf
backup: yes
- name: Init Galera cluster
block:
- name: 'Stop service "{{ db_servicename }}"'
service:
name: "{{ db_servicename }}"
state: stopped
- name: Create galera cluster
command: /usr/bin/galera_new_cluster
when: inventory_hostname == groups.db.0
when: db_settings.settings.wsrep_cluster_address == ""
- name: 'Enable service "{{ db_servicename }}"'
service:
name: "{{ db_servicename }}"
state: started
enabled: yes

21
templates/galera.cnf.j2 Normal file
View file

@ -0,0 +1,21 @@
[galera]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="webdb_cluster"
wsrep_cluster_address="gcomm://{% for h in groups['db'] %}{{ hostvars[h]['ansible_default_ipv4'].address }}{% if not loop.last %},{% endif %}{% endfor %}"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="{{ ansible_facts.default_ipv4.address }}"
wsrep_node_name="{{ ansible_hostname }}"