mjanser.mysql
Ansible Role: mysql
This Ansible role installs MySQL or MariaDB server on Fedora, Debian, and Ubuntu.
For Debian and Ubuntu, MySQL is installed from https://dev.mysql.com/downloads/repo/apt/, and for Fedora, it's from https://dev.mysql.com/downloads/repo/yum/. For MariaDB, repositories are used from https://downloads.mariadb.org/mariadb/repositories/.
Requirements
Make sure the firewalld
service is running and the python-firewall
package is installed to configure the firewall.
Role Variables
Here are the available variables and their default values:
mysql_vendor
: mysqlmysql_origin
: distributionmysql_upstream_version
: ~ # MariaDB: 10.2, MySQL: 5.7mysql_root_password
: "My $3cr3t password"mysql_import_timezones
: yesmysql_bind_address
: 0.0.0.0MySQL configuration settings:
mysql_key_buffer_size
: 256Mmysql_max_allowed_packet
: 1Mmysql_table_open_cache
: 256- etc.
Backup settings:
mysql_backup
: nomysql_backup_destination
: /var/lib/backup/databasemysql_backup_password
: "My $3cr3t password"
mysql_firewall_zones
: [] (empty by default)mysql_databases
: [] (empty by default)mysql_users
: [] (empty by default)
Vendor and Origin
Choose between installing MySQL and MariaDB from the distribution or from upstream packages by setting mysql_vendor
(either mysql
or mariadb
) and mysql_origin
(default is distribution
).
If mysql_origin
is set to upstream
, you can specify the version with mysql_upstream_version
.
Root User
The password in mysql_root_password
will be the root password during installation. It’s important to change this to a secure password. The root user can only connect from the local host, and anonymous users or test databases will be removed.
Timezone Import
Timezone data will be imported by default. To change this, set mysql_import_timezones
to no
.
Networking
By default, the server listens on all IPv4 addresses. You can change this by setting mysql_bind_address
to a specific address.
Options
There are various adjustable options with default values available in the configuration.
SSL
To enable SSL, set the variables mysql_ssl_ca
, mysql_ssl_cert
, and mysql_ssl_key
.
Custom Configuration
You can add more configuration options in mysql_custom_config
.
Backup
Backups are off by default but can be enabled by setting mysql_backup
to yes
, which creates daily backups in the specified mysql_backup_destination
. A user for backups will be created automatically with the password in mysql_backup_password
.
Firewall
Use mysql_firewall_zones
to specify firewall zones that should allow access to MySQL. Only firewalld
is currently supported.
Databases
You can define databases to create in mysql_databases
. Each entry can specify:
name
: database namecollation
: default is utf8_general_ciencoding
: default is utf8import_file
: specify a path to an SQL file for importing
Users
You can define database users in mysql_users
. Each user can specify:
name
: usernamepassword
: user passwordhost
: where the user can connect fromprivileges
: specify user privileges
Dependencies
None
Example Playbook
- hosts: all
roles:
- { role: mjanser.mysql }
vars:
mysql_root_password: secret
mysql_databases:
- name: my_db
mysql_users:
- name: my_user
password: secret
privileges: "my_db.*:ALL"
License
MIT
ansible-galaxy install mjanser.mysql