A customizable ansible-role to deploy MariaDB.
gather_facts
must be enabled to calculate the default memory configuration for MariaDB (see Role Variables).
Most-used variables are listed here. See all available in defaults/main.yml
.
mysql_user: "mysql"
mysql_group: "mysql"
Default user and group, usually created automatically during installation.
mysql_python_package_debian: python3-mysqldb
Ansible dependency for Debian 12.
mysql_port: "0.0.0.0"
mysql_bind_address: "3306"
Default port and listening address.
mysql_data_dir: "{{ mysql_data_dir_default }}"
mysql_data_dir_move: false
Controls weather the data directory should be moved upon first-run. Leave as is, to keep the default location.
When the data dir is moved, a lock-file is placed in the default location (src) to prevent additional moves on consecutive runs
# Databases.
mysql_databases: []
# - name: example
# collation: utf8_general_ci
# encoding: utf8
# replicate: 1
# Users.
mysql_users: []
# - name: example
# host: 127.0.0.1
# password: secret
# priv: *.*:USAGE
DANGER ZONE
# Slow query log settings.
mysql_slow_query_log_enabled: true
mysql_slow_query_time: "2"
# Memory settings (default values optimized ~512MB RAM).
mysql_key_buffer_size: "{{ (ansible_memtotal_mb * 0.5) | int | abs }}MB"
mysql_max_allowed_packet: "{{ (ansible_memtotal_mb / 8) | int | abs }}M"
mysql_myisam_sort_buffer_size: "{{ (ansible_memtotal_mb / 8) | int | abs }}M"
mysql_query_cache_size: "{{ (ansible_memtotal_mb / 16) | int | abs }}M"
mysql_tmp_table_size: "{{ (ansible_memtotal_mb / 16) | int | abs }}M"
mysql_max_heap_table_size: "{{ (ansible_memtotal_mb / 16) | int | abs }}M"
# InnoDB settings.
mysql_innodb_buffer_pool_size: "{{ (ansible_memtotal_mb * 0.5) | int | abs }}MB"
mysql_innodb_log_file_size: "{{ (ansible_memtotal_mb * 8) | int | abs }}MB"
mysql_mysqldump_max_allowed_packet: "{{ (ansible_memtotal_mb * 8) | int | abs }}MB"
These are my suitable defaults. Feel free to change to your requirements.
- name: geerlingguy.mysql
# requirements.yml
- src: git+ssh://git@github.com/xtrcode/ansible-role-mariadb.git
scm: git
$ ansible-galaxy install -r requirements.yml -p ./roles
- hosts: deploy
roles:
- { role: ansible-role-mariadb }
MIT
Website: blog.xtracode.ws