commit 0c855bf1c753fbd80e65e761abbeade2ee7b15a0 Author: Sven Velt Date: Tue Dec 1 22:05:58 2020 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75540da --- /dev/null +++ b/.gitignore @@ -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 + diff --git a/README.md b/README.md new file mode 100644 index 0000000..402c0db --- /dev/null +++ b/README.md @@ -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 +https://git.velt.biz/velt.biz/ + diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..dd2049a --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,8 @@ +--- +db_packages: + - mariadb-server + - python3-mysqldb + - rsync + +db_servicename: mysql + diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..a1e98df --- /dev/null +++ b/meta/main.yml @@ -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 + diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..472a110 --- /dev/null +++ b/tasks/main.yml @@ -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 + diff --git a/templates/galera.cnf.j2 b/templates/galera.cnf.j2 new file mode 100644 index 0000000..0128a5b --- /dev/null +++ b/templates/galera.cnf.j2 @@ -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 }}" +