This repository contains an Ansible role for installing and configuring [MariaDB](https://mariadb.org/) on Debian servers.
Versions of this role including and prior to [version 1.9.1](https://git.coop/webarch/mariadb/-/tree/1.9.1) require Ansible 2.9 and use the command and shell modules for many tasks, version 2.0.0 onwards requires Ansible 2.10 and uses the [community.mysql collection](https://docs.ansible.com/ansible/latest/collections/community/mysql/).
## Role versions
The `community.mysql` collection modules can be installed into `~/.ansible/collections/ansible_collections` like this:
Version 3.0.0 and greater of this role provide the option to edit or template MariaDB configuration files and use YAML dictionaries for the specification, existing files are read using [the JC ini parser](https://kellyjonbrazil.github.io/jc/docs/parsers/ini) and edited using the [community.general.ini_file module](https://docs.ansible.com/ansible/latest/collections/community/general/ini_file_module.html) or created or clobbered using the [ansible.builtin.template module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html).
```bash
ansible-galaxy collection install community.mysql
```
The last 2.x version of this role [version 2.4.2](https://git.coop/webarch/mariadb/-/releases/2.4.2) is the last version that contains Ansible tasks to switch between password and socket authentication for the root user, all 3.0.0 versions assume socket authentication is used.
Versions of this role including and prior to [version 1.9.1](https://git.coop/webarch/mariadb/-/tree/1.9.1) require Ansible 2.9 and use the command and shell modules for many tasks, version 2.0.0 onwards requires Ansible 2.10 and uses the [community.mysql collection](https://docs.ansible.com/ansible/latest/collections/community/mysql/).
This role can be used to [switch the root users authentication plugin from `unix_socket` to `mysql_native_password`](tasks/mariadb_root_password.yml) and [back](tasks/info_socket.yml) and it also runs `mysql_upgrade`, [imports](tasks/sys.yml) the [sys schema](https://github.com/webarch-coop/mariadb-sys), [updates the timezone data](tasks/tz.yml) when needed and sets [some systemd defaults](templates/mariadb.conf.j2).
This role adds [a script](templates/mariadb_root.fact.j2) to `/etc/ansible/facts.d` which results in the `ansible_local.mariadb_root.plugin` variable being generated with the value(s) of the root authentication plugins, `auth_socket`, `unix_socket` and / or `mysql_native_password`.
The primary URL of this repo is [`https://git.coop/webarch/mariadb`](https://git.coop/webarch/mariadb) and this is where the [release notes](https://git.coop/webarch/debug/-/releases) are, it is also [mirrored to GitHub](https://github.com/webarch-coop/ansible-role-debug) and [available via Ansible Galaxy](https://galaxy.ansible.com/chriscroome/debug).
## Defaults
See also the [defaults/main.yml](defaults/main.yml) file.
| `mariadb_mysqltuner_version` | `latest` | Set `latest` or a version from [the releases page](https://github.com/major/MySQLTuner-perl/releases), eg `v1.9.9` |
| `mariadb_sys_schema` | `false` | If `mariadb_sys_schema` is true then the sys schema is imported from [this repo](https://github.com/webarch-coop/mariadb-sys) |
| `mariadb_time_zone_import` | `true` | If `mariadb_time_zone_import` is true then the time zone tables when they have been updated |
| `mariadb_systemd_no_new_privileges` | `true` | Set systemd `NoNewPrivileges` to true for MariaDB |
| `mariadb_systemd_private_network` | `true` | Set systemd `PrivateNetwork` to true for MariaDB |
| `mariadb_systemd_private_tmp` | `true` | Set systemd `PrivateTmp` to true for MariaDB |
| `mariadb_transaction_isolation` | | Not defined by default, for [Nextcloud](https://docs.nextcloud.com/server/25/admin_manual/configuration_database/linux_database_configuration.html) |
| `mariadb_binlog_format` | | Not defined by default, for [Nextcloud](https://docs.nextcloud.com/server/25/admin_manual/configuration_database/linux_database_configuration.html) |
| `mariadb_query_cache_type` | `0` | |
| `mariadb_query_cache_limit` | `0` | |
| `mariadb_query_cache_size` | `0` | |
| `mariadb_root_auth` | `socket` | Set to `password` or `socket` to switch the root authentication plugin |
| `mariadb_username` | | Provide a `mariadb_username` to add a MariaDB user account |
| `mariadb_database` | | If `mariadb_username` is set and `mariadb_database` is not set then the DB value will default to `mariadb_username` |
| `mariadb_password` | | This variable is randomly generated and written to `/.my.cnf` or set to the value in `/.my.cnf` if it is present |
| `mariadb_priv` | | An array of user `PRIVILEGES`, if `mariadb_priv` is not set it defaults to `ALL` |
| `mariadb_mycnf` | | If a Linux user account exists that matches `mariadb_username` this will be set to `/home/{{ mariadb_username }}/.my.cnf` and if not `/root/{{ mariadb_username }}/.my.cnf` |
## Role variables
See the [defaults/main.yml](defaults/main.yml) file for the default variables, the [vars/main.yml](vars/main.yml) file for the preset variables and the [meta/argument_specs.yml](meta/argument_specs.yml) file for the variable specification.
### mariadb
### mariadb_config
### mariadb_mysqltuner
### mariadb_mysqltuner_version
### mariadb_pkgs
### mariadb_socket
### mariadb_systemd_units
### mariadb_sys_schema
## mariadb_time_zone_import
## Creating users and databases
...
...
@@ -71,7 +45,7 @@ You can call the `mariadb_user.yml` tasks multiple times, for example:
include_role:
name:mariadb
tasks_from:mariadb_user.yml
vars:
vars:
mariadb_database:wordpress
mariadb_username:wordpress
mariadb_priv:
...
...
@@ -109,3 +83,15 @@ You can call the `mariadb_user.yml` tasks multiple times, for example:
```
Note that the `mariadb_password` variable will contain the password for the last user created.
## Repository
The primary URL of this repo is [`https://git.coop/webarch/mariadb`](https://git.coop/webarch/mariadb) however it is also [mirrored to GitHub](https://github.com/webarch-coop/ansible-role-mariadb) and [available via Ansible Galaxy](https://galaxy.ansible.com/chriscroome/mariadb).
If you use this role please use a tagged release, see [the release notes](https://git.coop/webarch/mariadb/-/releases).
## Copyright
Copyright 2018-2023 Chris Croome, <[chris@webarchitects.co.uk](mailto:chris@webarchitects.co.uk)>.
This role is released under [the same terms as Ansible itself](https://github.com/ansible/ansible/blob/devel/COPYING), the [GNU GPLv3](LICENSE).
# This file is part of the Webarchitects MariaDB Ansible role.
#
# The Webarchitects MariaDB Ansible role is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
#
# The Webarchitects MariaDB Ansible role is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with the Webarchitects MariaDB Ansible role. If not, see <https://www.gnu.org/licenses/>.
---
-name:Install the MariaDB sys schema
-name:Install or remove the MariaDB sys schema
block:
-name:MariaDB sys repo directory present
ansible.builtin.file:
-name:Check if the MariaDB sys repo directory is present