Rolle zur Installation und Konfiguration eines MariaDB-Servers

This commit is contained in:
phil 2021-01-01 17:01:44 +00:00
commit 1d782e22e6
7 changed files with 86 additions and 0 deletions

8
defaults/main.yml Normal file
View file

@ -0,0 +1,8 @@
---
# defaults file for mariadb
munin_sql_user: munin
munin_sql_password: za8x5sECY6pP2GWdR36UKYP7tHFodvRLyr6f5wAt7D
mysql_server_config_file: /etc/mysql/mariadb.conf.d/50-server.cnf
mysql_socket: /var/run/mysqld/mysqld.sock

6
handlers/main.yml Normal file
View file

@ -0,0 +1,6 @@
---
- name: restart munin-node
service: name=munin-node state=restarted
- name: restart mysql
service: name=mariadb state=restarted

10
meta/main.yml Normal file
View file

@ -0,0 +1,10 @@
galaxy_info:
author: systemausfall.org
description: Role to setup MariaDB server
company: Sense.Lab
license: GPLv3
min_ansible_version: 2.9
plaforms:
- name: Debian
versions:
- Buster

6
tasks/main.yml Normal file
View file

@ -0,0 +1,6 @@
---
# tasks file for mariadb
- import_tasks: packages.yml
- import_tasks: munin.yml

39
tasks/munin.yml Normal file
View file

@ -0,0 +1,39 @@
- name: "Munin: sql-Nutzer anlegen"
mysql_user:
name: "{{ munin_sql_user }}"
password: "{{ munin_sql_password }}"
priv: '*.*:PROCESS,REPLICATION CLIENT'
state: present
login_unix_socket: "{{ mysql_socket }}"
login_user: root
- name: "Munin: Ersetze MariaDB-Zugangsdaten"
template:
src: templates/munin-mariadb.j2
dest: /etc/munin/plugin-conf.d/zzz-mariadb
notify: restart munin-node
- name: "Munin: Aktiviere mysql-Plugin"
command: munin-node-configure --shell | grep mysql_ | sh
# Ausgabe von fehlerhaften Plugins (exit 1) ignorieren
ignore_errors: yes
notify: restart munin-node
- name: "Munin: Aktiviere slowlog"
lineinfile:
path: "{{ mysql_server_config_file }}"
insertafter: ^# Enable the slow query
line: 'slow_query_log = 1'
notify: restart mysql
- name: "Munin: Konfiguriere slowlog"
lineinfile:
path: "{{ mysql_server_config_file }}"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^#slow_query_log_file', line: 'slow_query_log_file = /var/log/mysql/mariadb-slow.log' }
- { regexp: '^#long_query_time', line: 'long_query_time = 10' }
- { regexp: '^#log_slow_rate_limit', line: 'log_slow_rate_limit = 1000' }
- { regexp: '^#log_slow_verbosity', line: 'log_slow_verbosity = query_plan' }
notify: restart mysql

13
tasks/packages.yml Normal file
View file

@ -0,0 +1,13 @@
---
- name: "Packages: Fakten sammeln"
package_facts:
manager: apt
- name: "Packages: MariaDB-Server installieren"
apt:
pkg:
- default-mysql-server
- libcache-cache-perl
- python-pymysql
update_cache: yes
cache_valid_time: 3600

View file

@ -0,0 +1,4 @@
[mysql*]
env.mysqluser {{ munin_sql_user }}
env.mysqlpassword {{ munin_sql_password }}
env.mysqlconnection DBI:mysql:information_schema