mahdi22.mariadb_install

Ansible Role mariadb_install

This is an Ansible role for installing and securing MariaDB on RHEL/CentOS (7,8), Debian (9,10), and Ubuntu (20.04, 19.10, 18.04, 16.04). The role takes care of the following tasks:

  • Install MariaDB packages from official repositories
  • Configure the MariaDB server
  • Set the root password for the database
  • Remove anonymous users
  • Delete the test database
  • Disable remote access for the root user
  • Create a new database
  • Create a new database user
  • Import SQL scripts into the database

Installation

To install this role, use the command:

$ ansible-galaxy install mahdi22.mariadb_install

Role Variables

Basic Configuration

Variable Default Comments
mariadb_version '10.4' Set the MariaDB version (options vary by OS versions).
bind-address '127.0.0.1' IP address to listen on; use '0.0.0.0' for all interfaces.
configure_swappiness 'True' Set "swappiness" value if true.
create_database 'False' Set to 'True' to create a database.
database '' Name of the database to create (use with create_database).
port 3306 Port for client connections.
mysql_root_password 'azerty' Root password for MariaDB.
mariadb_service mariadb Name of the service.
swappiness '10' "Swappiness" value (default is 60).
create_db_user 'False' Set to 'True' to create a database user.
db_user_name '' Name of the user to be created (use with create_db_user).
db_user_password '' Password for the database user.
priviliges 'ALL' User database privileges.
mariadb_logrotate: rotate '7' Number of log rotations.
mariadb_logrotate: rotation 'daily' Rotation frequency for logs.
use_proxy 'False' Set to 'True' if behind a web proxy.
import_sql_file 'False' Set to 'True' to import SQL files into the databases.
sql_file_name '[]' List of SQL files to import (define if import_sql_file is true).

Notes

  1. To prevent remote access for the root user, set deny_remote_connections: true.
  2. It's important to set a root password for security! Leaving it empty poses a risk. Default is "azerty".
  3. To import SQL scripts, set import_sql_file: true, specify sql_file_name, and place scripts in the files directory.

Example Playbook

Using Default Parameters

- hosts: mariadb
  roles:
    - role: mahdi22.mariadb_install
      become: yes

Custom Variables Example

- hosts: mariadb
  roles:
    - role: mahdi22.mariadb_install
      become: yes
      vars:
        mariadb_version: "10.5"
        deny_remote_connections: true
        mysql_root_password: "azerty"
        create_database: true
        database: database_test
        create_db_user: true
        db_user_name: user_database
        db_user_password: password

Using Web Proxy Example

- hosts: mariadb
  roles:
    - role: mahdi22.mariadb_install
      become: yes
      vars:
        mariadb_version: "10.5"
        deny_remote_connections: true
        mysql_root_password: "azerty"
        create_database: true
        database: database_test
        create_db_user: true
        db_user_name: user_database
        db_user_password: password
        use_proxy: yes
        proxy_env:
          http_proxy: http://proxy.local:8080/
          https_proxy: http://proxy.local:8080/

Importing SQL Scripts Example

- hosts: mariadb
  roles:
    - role: mahdi22.mariadb_install
      become: yes
      vars:
        mariadb_version: "10.5"
        deny_remote_connections: true
        mysql_root_password: "azerty"
        create_database: true
        database: database_test
        create_db_user: true
        db_user_name: user_database
        db_user_password: password
        import_sql_file: true
        sql_file_name:
          - sqlscript1.sql
          - sqlscript2.sql
          - sqlscriptN.sql

Testing

This role has been tested on:

  • RHEL/CentOS 8
  • RHEL/CentOS 7
  • Debian 10
  • Debian 9
  • Debian 8
  • Ubuntu 20.04
  • Ubuntu 19.10
  • Ubuntu 18.04
  • Ubuntu 16.04
Informazioni sul progetto

Install and configure Mariadb server on Rhel/CentOS, Debian and Ubuntu ditributions

Installa
ansible-galaxy install mahdi22.mariadb_install
Licenza
mit
Download
1.6k
Proprietario