Default variable details
Some of debops.mariadb default variables have more extensive configuration
than simple strings or lists, here you can find documentation and examples for
them.
mariadb__databases
List of databases that should be present or absent on a given MariaDB server. Each database is defined as a YAML dict with the following keys:
databaseornameName of the database, required. Should be composed from alphanumeric characters and underscore (
_) only. Max length: 16 for MySQL databases, 80 for MariaDB databases.stateOptional. If value is
present, database will be created; ifabsent, database will be removed.sourceOptional. Path to a file with SQL dump on the Ansible Controller, which will be copied to the remote host at the
targetlocation, imported into database (only if it was recently created), and removed afterwards. The role does not check if the file exists before copying it, so make sure that it's present in the location that you specify beforehand.targetOptional. Path to a file on the remote host which will be imported to the database after it has been created (only once). The role does not check if the file exists before trying to import it. You can use the
sourceparameter to specify a file on the Ansible Controller to copy to thetargetlocation before import.target_deleteOptional. If present and
False, it will prevent deletion of target file on remote host.encodingOptional. Encoding mode to use, examples include
utf8orlatin1_swedish_ci.collationOptional. Collation mode (sorting). This only applies to new table/databases and does not update existing ones, this is a limitation of MySQL.
Examples
Create databases, remove some of the existing ones:
mariadb__databases:
- name: 'database1'
- name: 'database2'
- name: 'old_database'
state: 'absent'
Create a database and import its contents from a file already present on remote host:
mariadb__databases:
- name: 'fancy_db'
target: '/tmp/dbcontents.sql.gz'
Create a database and import its contents from a file on the Ansible Controller:
mariadb__databases:
- name: 'new_database'
source: '/tmp/database-contents.sql.gz'
target: '/tmp/dbcontents.sql.gz'
mariadb__users
List of user accounts that should be present or absent on a given MariaDB server. Each user account is defined as a dict with a set of keys and values.
User account parameters
userornameRequired. The "username" part of the user account on the MariaDB server. If
nameis specified, it will be used to determine the database name for granting default privileges, ifdatabaseis not specified.hostOptional. The "hostname" part of the user account on the MariaDB server. If not specified, it will be generated automatically by the role (this is usually what you want). It specifies the hostname or IP address of the host that is allowed to connect to the database.
passwordOptional. If specified, the role will set it as the password for the MariaDB account. If not present, a random password will be generated automatically and stored in the
secret/directory on the Ansible Controller. Refer to the debops.secret role for more details.stateOptional. If
present, the account will be created on the database server. Ifabsent, account will be removed from the database server.
Database privileges
databaseOptional. If present, it specifies the database name and/or database prefix that a given user account will be able to access using default privileges. If not present,
namewill be used instead.priv_defaultOptional. By default, the user accounts will get all privileges to databases with the same name. If this key is present and
False, the users will not get default privileges.priv_auxOptional. By default, the user accounts will get all privileges to the database prefixed with the name of the user account. If this key is present and
False, the users will not get default prefix privileges.privOptional. String or list of privileges to grant to a given user account. See
mysql_userdocumentation for information about how to specify the privileges.append_privsOptional. If present and
True, specified privileges will be appended to already existing privileges (default). IfFalse, specified privileges will replace all current privileges for a given user account.
User configuration file
ownerOptional. It should specify a local UNIX account on the host managed by the
debops.mariadbrole (not on the host with the database, unless it's a local installation). If specified, thedebops.mariadbrole will create a local UNIX account if it doesn't exist with the specified name and create a~/.my.cnfconfiguration file with the MariaDB account credentials and configuration pointing to the MariaDB server.groupOptional. Main local UNIX group of the created account. If not specified, a group named after the account will be created instead.
homeRequired if
item.owneris specified. Specifies the home directory of given local UNIX account.systemOptional. If specified and
True, the local UNIX group/user account which is going to be created will be a "system" account with UID/GID < 1000. If specified andFalse, local UNIX group/user account will be a "normal" account with UID/GID >= 1000. By default groups and accounts will be created as "system" accounts.modeOptional. If specified, defines the permissions of the
~/.my.cnfconfiguration file. By default they are set to0640.creds_pathOptional, string. Allows you to change the file path for the credentials file which defaults to
~/.my.cnf.
Examples
Create a MariaDB user account with all privileges granted to the someuser.* and
someuser\_%.* databases:
mariadb__users:
- name: 'someuser'
Create a MariaDB user account with all privileges to somedatabase.*
without auxiliary privileges:
mariadb__users:
- name: 'someuser'
database: 'somedatabase'
priv_aux: False
Create a MariaDB user account and set up a local system account configured to use MariaDB:
mariadb__users:
- name: 'someuser'
owner: 'system-user'
home: '/var/local/system-user'
Create a MariaDB user account without default privileges:
mariadb__users:
- name: 'someuser'
priv_default: False
priv_aux: False
Create a MariaDB user account with custom additional privileges:
mariadb__users:
- name: 'someuser'
priv: [ 'otherdb.*:ALL' ]
mariadb__options
The role uses /etc/mysql/conf.d/client.cnf configuration file to manage the
MariaDB/MySQL system-wide client configuration. This configuration file is
generated by a template that uses the mariadb__client_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__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__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:
nameRequired for the main options. Name of the option to add.
sectionRequired for the definition of a configuration section. Create new section of the configuration file, written in square brackets.
stateOptional. Either
presentorabsent. If not specified orpresent, a given section or option will be added in the configuration file; ifabsent, option or section won't be added.commentOptional. Add a comment to a given option or section.
valueOptional for main options. If specified, set a value of a given option.
optionsOptional. 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
nameandvalueare ignored.
Examples:
mariadb__options:
- section: 'client'
comment: 'Global MariaDB client options'
options:
- name: 'skip_name_resolve'
- name: 'key_buffer'
value: '16M'
- name: 'query_cache_type'
value: '0'
state: 'present'