This page contains links to Ansible modules and roles that can be used to automate MariaDB deployment and configuration. The list is not meant to be exhaustive. Use it as a starting point, but then please do your own research.
At the time time of writing, there are no MariaDB-specific modules in Ansible Galaxy. MySQL modules can be used. Trying to use MySQL-specific features may result in errors or unexpected behavior. However, the same applies when trying to use a feature not supported by the MySQL version in use.
Currently, the MySQL collection in Ansible Galaxy contains at least the following modules:
Note that some modules only exist as shortcuts, and it is possible to use mysql_query instead. However, it is important to notice that mysql_query is not idempotent. Ansible does not understand MySQL queries, therefore it cannot check whether a query needs to be run or not.
To install this collection locally:
ansible-galaxy collection install community.mysql
MariaDB Corporation maintains a ColumnStore playbook on GitHub.
Let's see some other modules that are useful to manage MariaDB servers.
Modules like shell and command allow one to run system commands.
To deploy on Windows, win_shell and win_command can be used.
Among other things, it is possible to use one of these modules to run MariaDB queries:
- name: Make the server read-only # become root to log into MariaDB with UNIX_SOCKET plugin become: yes shell: $( which mysql ) -e "SET GLOBAL read_only = 1;"
The main disadvantage with these modules is that they are not idempotent, because they're meant to run arbitrary system commands that Ansible can't understand. They are still useful in a variety of cases:
An important part of configuration management is copying configuration files to remote servers.
The copy module allows us to copy files to target hosts. This is convenient for static files that we want to copy exactly as they are. An example task:
- name: Copy my.cnf
copy:
src: ./files/my.cnf.1
dest: /etc/mysql/my.cnf
As you can see, the local name and the name on remote host don't need to match. This is convenient, because it makes it easy to use different configuration files with different servers. By default, files to copy are located in a files subdirectory in the role.
However, typically the content of a configuration file should vary based on the target host, the group and various variables. To do this, we can use the template module, which compiles and copies templates written in Jinja.
A simple template task:
- name: Compile and copy my.cnf
copy:
src: ./templates/my.cnf.j2
dest: /etc/mysql/my.cnf
Again, the local and the remote names don't have to match. By default, Jinja templates are located in a templates subdirectory in the role, and by convention they have the .j2 extension. This is because Ansible uses Jinja version 2 for templating, at the time writing.
A simple template example:
## WARNING: DO NOT EDIT THIS FILE MANUALLY !!
## IF YOU DO, THIS FILE WILL BE OVERWRITTEN BY ANSIBLE
[mysqld]
innodb_buffer_pool_size = {{ innodb_buffer_pool_size }}
{% if use_connect sameas true %}
connect_work_size = {{ connect_work_size }}
{% endif %}
The following modules are also often used for database servers:
Specific roles exist for MariaDB in Ansible Galaxy. Using them for MariaDB is generally preferable, to be sure to avoid incompatibilities and to probably be able to use some MariaDB specific features. However, using MySQL or Percona Server roles is also possible. This probably makes sense for users who also administer MySQL and Percona Server instances.
To find roles that suits you, check Ansible Galaxy search page. Most roles are also available on GitHub.
You can also search roles using the ansible-galaxy tool:
ansible-galaxy search mariadb
Content initially contributed by Vettabase Ltd.
© 2023 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/existing-ansible-modules-and-roles-for-mariadb/