DEBOPS.MARIADB_SERVER(5)

NAME
debops.mariadb_server - Manage MariaDB database server

SYNOPSIS

debops service/mariadb_server [--limit group,host,...] [--diff] [--check] [--tags tag1,tag2,...] [--skip-tags tag1,tag2,...] [<ansible-playbook options>] ...

DESCRIPTION

MariaDB <https://en.wikipedia.org/wiki/Mariadb> is a popular relational SQL database that was forked from MySQL server. Ansible roles debops.mariadb and debops.mariadb_server allow you to manage a MariaDB server and / or access it remotely from other hosts.

debops.mariadb_server role is the "server" part - it installs mariadb-server Debian package, and configures access to the database from local root account. After that, you can use debops.mariadb role to manage databases and user accounts on the server.

GETTING STARTED

  Example inventory

To install MariaDB on a host, you need to add it to [debops_service_mariadb_server] Ansible group:

[debops_service_mariadb_server]
database-host

This will install mariadb-server package, configure the server to listen on localhost for new connections, and install automysqlbackup script to automatically create daily, weekly and monthly backups of the database.

  Example playbook

Here's an example Ansible playbook that uses the debops.mariadb_server role:

---
- name: Manage MariaDB server
  collections: [ 'debops.debops', 'debops.roles01',
                 'debops.roles02', 'debops.roles03' ]
  hosts: [ 'debops_service_mariadb_server' ]
  become: True
  environment: '{{ inventory__environment | d({})
                   | combine(inventory__group_environment | d({}))
                   | combine(inventory__host_environment  | d({})) }}'
  roles:
    - role: keyring
      tags: [ 'role::keyring', 'skip::keyring', 'role::mariadb_server' ]
      keyring__dependent_apt_keys:
        - '{{ mariadb_server__keyring__dependent_apt_keys }}'
    - role: etc_services
      tags: [ 'role::etc_services' ]
      etc_services__dependent_list:
        - '{{ mariadb_server__etc_services__dependent_rules }}'
    - role: ferm
      tags: [ 'role::ferm', 'skip::ferm' ]
      ferm__dependent_rules:
        - '{{ mariadb_server__ferm__dependent_rules }}'
    - role: tcpwrappers
      tags: [ 'role::tcpwrappers', 'skip::tcpwrappers' ]
      tcpwrappers__dependent_allow:
        - '{{ mariadb_server__tcpwrappers__dependent_allow }}'
    - role: python
      tags: [ 'role::python', 'skip::python', 'role::mariadb_server' ]
      python__dependent_packages3:
        - '{{ mariadb_server__python__dependent_packages3 }}'
      python__dependent_packages2:
        - '{{ mariadb_server__python__dependent_packages2 }}'
    - role: mariadb_server
      tags: [ 'role::mariadb_server', 'skip::mariadb_server' ]

  Remote access to the database

If you want to allow connections from remote hosts to the MariaDB server, you need to change the bind address to listen on all network interfaces, and specify the list of IP addresses or CIDR networks which can connect to the daemon:

mariadb_server__bind_address: '::'
mariadb_server__allow: [ '192.0.2.0/24', '2001:db8:3232::/64' ]

Changing the bind address will require the MariaDB daemon to be restarted, however debops.mariadb_server does not do that automatically to avoid disrupting the normal server operations. To restart the service, you can run this Ansible command:

user@host:~$ ansible database-host -b -m service -a 'name=mysql state=restarted'

Note the mysql service name - MariaDB still uses the old MySQL init files, configuration and data paths to allow easy compatibility with old MySQL installations.

  Database and user management

debops.mariadb_server is not meant to be used to manage databases and user accounts. You should use debops.mariadb role instead, which was designed specifically for this purpose.

DEFAULT VARIABLE DETAILS

Some of debops.mariadb_server default variables have more extensive configuration than simple strings or lists, here you can find documentation and examples for them.

  mariadb_server__options

The role uses /etc/mysql/conf.d/mysqld.cnf configuration file to manage the MariaDB/MySQL server configuration. This configuration file is generated by a template that uses the mariadb_server__mysqld_options variable to get the configuration data. The configuration itself is split among several variables located in defaults/main.yml file.

A minimal configuration is stored as a YAML dictionary. Keys of the dictionary as MariaDB configuration option names, and values of the dictionary are the configuration values. All values are automatically quoted in the generated configuration file.

Example configuration section:

mariadb_server__options:
  'query_cache_type': '0'
  'key_buffer': '16M'
  'skip_name_resolve':

The dictionary keys without values will be written in the configuration file with correct notation.

Alternative configuration notation is to use a YAML list, each element of a list being a YAML dictionary in the above format. An example:

mariadb_server__options:
  - 'query_cache_type': '0'
    'key_buffer': '16M'
  - 'skip_name_resolve':

Yet another alternative format can be used if you use certain keys in the YAML dictionary. The template checks for presence of the name or section keys, and if found, changes to a different format that uses YAML dictionary keys:

name
    Required for the main options. Name of the option to add.

section
    Required for the definition of a configuration section. Create new section of the configuration file, written in square brackets.

state
    Optional. Either present or absent. If not specified or present, a given section or option will be added in the configuration file; if absent, option or section won't be added.

comment
    Optional. Add a comment to a given option or section.

value
    Optional for main options. If specified, set a value of a given option.

options
    Optional. A YAML dictionary or list of YAML dictionaries with options to include in a given section, or multiple options specified together as a group. If it's specified, values of name and value are ignored.

    Examples:

    mariadb_server__options:
      - section: 'mysqld'
        comment: 'Global MariaDB server options'
        options:
          - name: 'skip_name_resolve'
          - name: 'key_buffer'
            value: '16M'
          - name: 'query_cache_type'
            value: '0'
            state: 'present'

AUTHOR
Maciej Delmanowski

COPYRIGHT
2014-2022, Maciej Delmanowski, Nick Janetakis, Robin Schneider and others