From 6b3d265524cae63d359b9823a8d42d2cd0cfa471 Mon Sep 17 00:00:00 2001 From: phil Date: Sat, 14 Oct 2023 10:43:06 +0200 Subject: [PATCH] Configure MariDB server via this role --- README.md | 18 ++++++------------ defaults/main.yml | 14 ++++++++++---- templates/automysqlbackup.j2 | 8 ++++---- templates/mariadb.conf.j2 | 14 +++++++------- templates/monit.conf.j2 | 2 ++ templates/munin-mariadb.conf.j2 | 4 +++- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index d30cae2..2686549 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,14 @@ This role installs MariaDB, including: - Monitoring with Monit and Munin - Backups with automysqlbackup -No configuration of the database server will take place. +## Configuration -## Variables - -You can use the following variables to adopt the role to your needs. Place them in a dictionary called `mariadb`: - -| Varible | Value | Notes | -|--|--|--| -| `bind_address` | string | Address to bind the MariaDB server to | - -Ecample: +Create a dictionary called `mysqld` and define your settings: ```YAML -mariadb: - bind_address: "10.0.0.2" +mysqld: + bind_address: 0.0.0.0 + slow_query_log: 1 + ... ``` There are additional variables to configure automysqlbackup: diff --git a/defaults/main.yml b/defaults/main.yml index cd1fc62..b66467e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,8 +7,14 @@ munin_sql_password: "{{ lookup('ansible.builtin.password', '/tmp/{{ inventory_ho mysql_socket: /run/mysqld/mysqld.sock -slowlog_query_log_file: /var/log/mysql/mariadb-slow.logA -slowlog_query_time: 10 -slowlog_log_slow_rate_limit: 1000 - +automysqlbackup_backupdir: /var/lib/automysqlbackup +automysqlbackiup_dbhost: localhost +automysqlbackup_mailaddr: root automysqlbackup_postbackup: /usr/local/bin/automysqlbackup_post_script + +mysqld: + slow_query_log: 1 + slowlog_query_log_file: /var/log/mysql/mariadb-slow.logA + slowlog_query_time: 10 + slowlog_log_slow_rate_limit: 1000 + log_slow_verbosity: query_plan diff --git a/templates/automysqlbackup.j2 b/templates/automysqlbackup.j2 index 1262f3e..3deb2f3 100644 --- a/templates/automysqlbackup.j2 +++ b/templates/automysqlbackup.j2 @@ -1,11 +1,11 @@ -# Managed by ansible +# {{ ansible_managed }} -DBHOST={{ automysqlbackiup_dbhost | default("localhost") }} +DBHOST={{ automysqlbackiup_dbhost }} DBNAMES=`mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW DATABASES" | awk '{print $1}' | grep -v ^Database$ | grep -v ^mysql$ | grep -v ^performance_schema$ | grep -v ^information_schema$ | tr \\\r\\\n ,\ ` -BACKUPDIR="{{ automysqlbackup_backupdir | default("/var/lib/automysqlbackup") }}" +BACKUPDIR="{{ automysqlbackup_backupdir }}" MAILCONTENT="quiet" MAXATTSIZE="4000" -MAILADDR="{{ automysqlbackup_mailaddr | default("root") }}" +MAILADDR="{{ automysqlbackup_mailaddr }}" MDBNAMES="mysql $DBNAMES" DBEXCLUDE="" CREATE_DATABASE=yes diff --git a/templates/mariadb.conf.j2 b/templates/mariadb.conf.j2 index a533a04..d338d90 100644 --- a/templates/mariadb.conf.j2 +++ b/templates/mariadb.conf.j2 @@ -1,9 +1,9 @@ -# Ansible managed +# {{ ansible_managed }} [mysqld] -# slow log -slow_query_log = 1 -slow_query_log_file = {{ slowlog_query_log_file }} -long_query_time = {{ slowlog_query_time }} -log_slow_rate_limit = {{ slowlog_log_slow_rate_limit }} -log_slow_verbosity = query_plan + +{% if mysqld_config is defined %} +{% for key, value in mysqld_config.items() %} +{{ key }} = {{ value }} +{% endfor %} +{% endif %} diff --git a/templates/monit.conf.j2 b/templates/monit.conf.j2 index 4e4c857..130a636 100644 --- a/templates/monit.conf.j2 +++ b/templates/monit.conf.j2 @@ -1,3 +1,5 @@ +# {{ ansible_managed }} + check process mariadb with pidfile /run/mysqld/mysqld.pid group database start program = "/usr/sbin/service mysql start" diff --git a/templates/munin-mariadb.conf.j2 b/templates/munin-mariadb.conf.j2 index 2cc5df7..01c5b14 100644 --- a/templates/munin-mariadb.conf.j2 +++ b/templates/munin-mariadb.conf.j2 @@ -1,4 +1,6 @@ +# {{ ansible_managed }} + [mysql*] env.mysqluser {{ munin_sql_user }} env.mysqlpassword {{ munin_sql_password }} -env.mysqlconnection DBI:mysql:information_schema \ No newline at end of file +env.mysqlconnection DBI:mysql:information_schema