• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    Shell
  • License
    Other
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Install MariaDB on RHEL/CentOS 7 or Fedora.

Ansible role mariadb

An Ansible role for managing MariaDB in RedHat-based distributions. Specifically, the responsibilities of this role are to:

  • Install MariaDB packages from the official MariaDB repositories
  • Remove unsafe defaults:
    • set database root password (remark that once set, this role is unable to change the database root password)
    • remove anonymous users
    • remove test database
  • Create users and databases
  • Manage configuration files server.cnf and custom.cnf
  • Upload SSL certificates and configure the server to use them

Refer to the change log for notable changes in each release.

Do you use/like this role? Please consider giving it a star. If you rate this role on Ansible Galaxy and find it lacking in some respect, please consider opening an Issue with actionable feedback or a PR so we can improve it. Thank you!

Requirements

No specific requirements

Role Variables

None of the variables below are required. When not defined by the user, the default values are used.

Basic configuration

Variable Default Comments
mariadb_bind_address '127.0.0.1' Set this to the IP address of the network interface to listen on, or '0.0.0.0' to listen on all interfaces.
mariadb_configure_swappiness true When true, this role will set the "swappiness" value (see mariadb_swappiness.
mariadb_custom_cnf {} Dictionary with custom configuration.
mariadb_databases [] List of dicts specifying the databases to be added. See below for details.
mariadb_mirror yum.mariadb.org Download mirror for the .rpm package (1)
mariadb_port 3306 The port number used to listen to client requests
mariadb_root_password '' The MariaDB root password. (2)
mariadb_server_cnf {} Dictionary with server configuration.
mariadb_service mariadb Name of the service (should e.g. be 'mysql' on CentOS for MariaDB 5.5)
mariadb_swappiness '0' "Swappiness" value (string). System default is 60. A value of 0 means that swapping out processes is avoided.
mariadb_users [] List of dicts specifying the users to be added. See below for details.
mariadb_version '10.5' The version of MariaDB to be installed. Default is the current stable release.
mariadb_ssl_ca_crt null Path to the certificate authority's root certificate
mariadb_ssl_server_crt null Path to the server's SSL certificate
mariadb_ssl_server_key null Path to the server's SSL certificate key

Remarks

(1) Installing MariaDB from the official repository can be very slow (some users reported more than 10 minutes). The variable mariadb_mirror allows you to specify a custom download mirror closer to your geographical location that may speed up the installation process. E.g.:

# for RHEL/Fedora
mariadb_mirror: 'mariadb.mirror.nucleus.be/yum'
# for Debian
mariadb_mirror: 'mirror.mva-n.net/mariadb/repo'

(2) It is highly recommended to set the database root password! Leaving the password empty is a serious security risk. The role will issue a warning if the variable was not set.

Server configuration

You can specify the configuration in /etc/my.cnf.d/server.cnf (in RHEL/Fedora, /etc/mysql/conf.d/server.cnf in Debian), specifically in the [mariadb] section, by providing a dictionary of keys/values in the variable mariadb_server_cnf. Please refer to the MariaDB Server System Variables documentation for details on the possible settings.

For settings that don't get a = value in the config file, leave the value empty. All values should be given as strings, so numerical values should be quoted.

In the following example, slow-query-log's value is left empty:

mariadb_server_cnf:
  slow-query-log:
  slow-query-log-file: 'mariadb-slow.log'
  long-query-time: '5.0'

This would result in the following server.cnf:

[mariadb]
slow-query-log
slow-query-log-file = mariadb-slow.log
long-query-time = 5.0

Custom configuration

Settings for other sections than [mariadb], can be set with mariadb_custom_cnf. These settings will be written to /etc/mysql/my.cnf.d/custom.cnf (in RHEL/Fedora, /etc/mysql/conf.d/custom.cnf in Debian).

Just like mariadb_server_cnf, the variable mariadb_custom_cnf should be a dictionary. Keys are section names and values are dictionaries with key-value mappings for individual settings.

The following example enables the general query log:

mariadb_custom_cnf:
  mysqld:
    general-log:
    general-log-file: queries.log
    log-output: file

The resulting config file will look like this:

[mysqld]
general-log-file=queries.log
general-log
log-output=file

Adding databases

Databases are defined with a dict containing the fields name: (required), and init_script: (optional). The init script is a SQL file that is executed when the database is created to initialise tables and populate it with values.

mariadb_databases:
  - name: appdb1
  - name: appdb2
    init_script: files/init_appdb2.sql

Adding users

Users are defined with a dict containing fields name:, password:, priv:, and, optionally, host:, and append_privs. The password is in plain text and priv: specifies the privileges for this user as described in the Ansible documentation.

An example:

mariadb_users:
  - name: john
    password: letmein
    priv: '*.*:ALL,GRANT'
  - name: jack
    password: sekrit
    priv: 'jacksdb.*:ALL'
    append_privs: 'yes'
    host: '192.168.56.%'

Dependencies

No dependencies.

Example Playbook

See the test playbook

Testing

This role can be tested using Ansible Molecule. The Molecule configuration will:

  • Run Yamllint and Ansible Lint
  • Create a Docker container named db
  • Run a syntax check
  • Apply the role with a test playbook
  • Run acceptance tests with BATS

This process is repeated for each supported Linux distribution.

Local Docker test environment

If you want to set up a local test environment, you can use this reproducible setup based on Vagrant+VirtualBox: https://github.com/bertvv/ansible-testenv. Steps to install the necessary tools manually:

  1. Docker and BATS should be installed on your machine (assumed to run Linux). No Docker containers should be running when you start the test.
  2. As recommended by Molecule, create a python virtual environment
  3. Install the software tools python3 -m pip install molecule docker netaddr yamllint ansible-lint
  4. Navigate to the root of the role directory and run molecule test

Molecule automatically deletes the containers after a test. If you would like to check out the containers yourself, run molecule converge followed by molecule login --host HOSTNAME.

The Docker containers are based on images created by Jeff Geerling, specifically for Ansible testing (look for images named geerlingguy/docker-DISTRO-ansible). You can use any of his images, but only the distributions mentioned in meta/main.yml are supported.

The default config will start a Centos 7 container (the primary supported platform at this time). Choose another distro by setting the MOLECULE_DISTRO variable with the command, e.g.:

MOLECULE_DISTRO=fedora32 molecule test

or

MOLECULE_DISTRO=fedora32 molecule converge

You can run the acceptance tests on both servers with molecule verify or manually with

SUT_IP=172.17.0.2 bats molecule/common/mariadb.bats

You need to initialise the variable SUT_IP, the system under test's IP address. The db container should have IP address 172.17.0.2

Local Vagrant test environment

Alternatively, you can run the Molecule tests with full-fledged VMs instead of Docker containers. Vagrant, VirtualBox, Ansible, Molecule and BATS need to be installed on the system where you run the tests.

molecule test -s vagrant

This will create VirtualBox VMs for the supported platforms, based on base boxes from the Bento project, apply the test playbook and run acceptance tests.

License

2 clause BSD

Contributors

More Repositories

1

cheat-sheets

Cheat sheets for various stuff
Makefile
311
star
2

ansible-role-bind

Sets up ISC BIND as an authoritative DNS server on several Linux distros & FreeBSD
Jinja
255
star
3

ansible-role-samba

Ansible role for managing Samba as a file server on RedHat- and Debian-based linux distros.
Shell
189
star
4

ansible-skeleton

An opinionated skeleton for Ansible projects with a development environment powered by Vagrant.
Shell
100
star
5

dotfiles

My configuration for Bash, Ruby, Git, Todo.txt, Vim, etc. See Wiki for usage instructions.
Vim Script
64
star
6

ansible-role-dhcp

Ansible role for setting up ISC DHCPD on RHEL/CentOS 7
Jinja
58
star
7

github-org-mgmt

Scripts for automating Github organisation management, e.g. creating teams with a repo and adding members.
Python
48
star
8

ansible-dnsmasq

An Ansible role for managing Dnsmasq on RHEL/CentOS 7 of Fedora with basic DNS and DHCP capabilities.
46
star
9

scripts

A bunch of (mostly Bash) scripts that may be useful. Or not.
Shell
45
star
10

ansible-role-pxeserver

Ansible role to set up a PXE server on RHEL/CentOS 7
Ruby
38
star
11

ansible-role-rh-base

Ansible role for basic setup of a server with a RedHat-based Linux distribution (CentOS, Fedora, RHEL, ...)
Shell
32
star
12

ansible-role-hosts

An Ansible role for managing the hosts file (`/etc/hosts`).
32
star
13

ansible-role-httpd

A simple Ansible role for installing and configuring the Apache web server for RHEL/CentOS 7 and Fedora 28
Jinja
31
star
14

ansible-role-vsftpd

Set up an FTP server with Vsftpd on RHEL/CentOS 7, Ubuntu 12.04, or 14.04
26
star
15

vagrant-shell-skeleton

Scaffolding code for a multi-VM Vagrant environment with Shell provisioning.
Shell
19
star
16

ansible-role-wordpress

Installs Wordpress on RHEL/CentOS 7
PHP
17
star
17

ansible-toolbox

A collection of scripts to be used with ansible-skeleton and ansible-role-skeleton
Shell
15
star
18

ansible-role-skeleton

My scaffolding code for Ansible roles. Setting up manually is not recommended. A script to initialise a new role can be found here: https://github.com/bertvv/ansible-toolbox/
Shell
13
star
19

linux-network-troubleshooting

Guide for troubleshooting network services on a Linux system
13
star
20

ansible-role-el7

An Ansible role for basic configuration of RHEL/CentOS 7 based machines.
Shell
11
star
21

ansible-role-jblicense

Installs JetBrains License Server on RHEL/CentOS 7
Ruby
10
star
22

ansible-role-tftp

Installs a TFTP server on RHEL/CentOS 7
10
star
23

ansible-role-mailserver

Installation of a complete mail server (Postfix, Cyrus, ...) on Enterprise Linux 7
10
star
24

docker-images-ansible

Docker images for testing Ansible roles
Dockerfile
7
star
25

ansible-role-tomcat

An Ansible role for setting up Tomcat on RHEL/CentOS 7 or Fedora.
7
star
26

presentation-el7-basics

My presentation at CentOS Dojo 2017 Brussels, "Basic commands for Enterprise Linux 7"
CSS
6
star
27

vagrant-presentation

Presentation slides of my Vagrant tutorial at LOADays 2014
HTML
6
star
28

ansible-role-collectd

Installs collectd (client and server) and, optionally, collectd-web on RHEL/CentOS 7
Jinja
5
star
29

bachproef-gids

**LET OP** deze repo is verhuisd naar
4
star
30

presentation-network-troubleshooting

My presentation for CentOS Dojo 2018 Brussels, and LOADays 2018: Basic troubleshooting of network services in EL7
Shell
4
star
31

ansible-role-sambadc

Proof-of-concept Samba4 as Domain Controller on CentOS7
3
star
32

presentation-clean-bash

Slides and supporting material for my "Clean Bash" talk at Loadays 2019
3
star
33

travispoc

Proof-of-Concept for running an Ansible playbook inside a Docker container with CentOS on Travis-CI
3
star
34

presentation-linux-hogent

Slide deck for my talk "Linux curriculum at HOGENT" for LOADays 2019
2
star
35

server-dotfiles

Configuration for Bash, Vim, Tmux, etc.
Vim Script
2
star
36

ansible-role-cobbler

Installs and configures Cobbler (with Dnsmasq) on RHEL/CentOS 7 (not ready for release)
Ruby
2
star
37

vagrant-example

The example I used in my Vagrant tutorial at LOADays 2014
Puppet
2
star
38

hogent-latex-sjablonen

LaTeX sjablonen met de huisstijl van HoGent (Bedrijf en Organisatie) LET OP, voor een recente versie van het sjabloon voor de bachelorproef, ga naar https://github.com/HoGentTIN/bachproef-latex-sjabloon
TeX
2
star
39

presentation-cfgmgmtcamp2017

Slides for my presentation at Configuration Management Camp Ghent 2017
CSS
1
star
40

fedora-testbox

A minimal Fedora installation for experimenting with Linux
Shell
1
star
41

docker-sandbox

Vagrant environment of a Fedora 27 VM running Docker and Cockpit
Shell
1
star
42

ansible-role-drupal

Install Drupal on RHEL/CentOS 7
PHP
1
star
43

notes-to-self

Content of my blog
Shell
1
star
44

gitbash-dotfiles

Dotfiles for my Git Bash (on Windows) environment
Shell
1
star
45

today-i-learned

Today, I learned...
Shell
1
star
46

talks

Slide decks for talks I've given
CSS
1
star