A simple MariaDB deployment with Ansible
Here's a simple Ansible Playbook to create a basic MariaDB deployment.
The basic steps the playbook will attempt are:
- Install a few libraries
- Setup Repos
- Install MariaDB packages
- Install Percona software
- Create MariaDB directories
- Copy my.cnf to server (note this is a template file and not supplied here)
- Run mysql_install_db if needed
- Start MariaDB
- Set root password
- Delete anonymous users
- Create myapp database and user
Note: some steps will only execute if a root password has not been set. These are identifiable by the following line:
when: is_root_password_set.rc == 0
This is the playbook in full:
PLAY [database] *********************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************
ok: [db01]
TASK [Install Utility software] *****************************************************************************************************************************
changed: [db01] => (item=[u'software-properties-common', u'python-mysqldb'])
TASK [Add apt key] ******************************************************************************************************************************************
changed: [db01]
TASK [Add MariaDB Repo] *************************************************************************************************************************************
changed: [db01]
TASK [Get Key for Percona Repo] *****************************************************************************************************************************
changed: [db01]
TASK [Add Percona Tools Repo] *******************************************************************************************************************************
changed: [db01]
TASK [Install MariaDB Packages] *****************************************************************************************************************************
changed: [db01] => (item=[u'mariadb-client', u'mariadb-common', u'mariadb-server'])
TASK [Install Percona Software] *****************************************************************************************************************************
changed: [db01] => (item=[u'percona-toolkit', u'percona-xtrabackup', u'percona-nagios-plugins'])
TASK [Create MariaDB Directories] ***************************************************************************************************************************
changed: [db01] => (item=db)
changed: [db01] => (item=log)
TASK [Write new configuration file] *************************************************************************************************************************
changed: [db01]
TASK [Count files in /data/db] ******************************************************************************************************************************
ok: [db01]
TASK [Run mysql_install_db only if /data/db is empty] *******************************************************************************************************
changed: [db01]
TASK [Start MariaDB] ****************************************************************************************************************************************
ok: [db01]
TASK [Is root password set?] ********************************************************************************************************************************
changed: [db01]
TASK [Delete anonymous users] *******************************************************************************************************************************
ok: [db01]
TASK [Generate mysql root password] *************************************************************************************************************************
changed: [db01]
TASK [Set root password] ************************************************************************************************************************************
changed: [db01]
TASK [Set root password for other hosts] ********************************************************************************************************************
changed: [db01] => (item=127.0.0.1)
changed: [db01] => (item=::1)
TASK [Inform user of mysql root password] *******************************************************************************************************************
ok: [db01] => {
"changed": false,
"msg": "MariaDB root password was set to zr2MuEXUBD"
}
TASK [Create myapp database] ********************************************************************************************************************************
changed: [db01]
TASK [Generate myapp_rw password] ***************************************************************************************************************************
changed: [db01]
TASK [Create user for myapp db] *****************************************************************************************************************************
changed: [db01]
PLAY RECAP **************************************************************************************************************************************************
db01 : ok=22 changed=17 unreachable=0 failed=0