Ticket ID #199 ‐ Create and Apply Puppet Module for MariaDB on DB Server - GriffinKat/group-a GitHub Wiki

Creating a Puppet module that installs and manages MariaDB on the database server

Create the files and directory structure for MariaDB

image

Using these commands

cd /etc/puppetlabs/code/modules
sudo mkdir mariadb
cd mariadb
sudo mkdir files
cd files
sudo touch 50-server.cnf
cd ..

sudo mkdir manifests
sudo touch {init.pp,install.pp,config.pp,service.pp}
cd..

sudo mkdir templates
cd ..

To install Mariadb and its dependencies

Paste this code into install.pp

cd manifests
sudo touch install.pp

class mariadb::install {
package { "mariadb-server":
ensure => present,
require => User["mysql"],
}

user {
"mysql": ensure => present,
comment => "MariaDB user",
gid => "mysql",
shell => "/bin/false",
require => Group["mysql"],
}

group { "mysql":
ensure => present,
}
}

This class ensures that the mariadb-server package is installed

Paste this code into config.pp

sudo touch config.pp

class mariadb::config
{ file { "/etc/mysql/mariadb.conf.d/50-server.cnf":
ensure => present,
source => "puppet:///modules/mariadb/50-server.cnf",
mode => "0444",
owner => "root",
group => "root",
require => Class["mariadb::install"],
notify => Class["mariadb::service"],
}
}

This class ensures that the MariaDB configuration file is placed in the correct location

Paste this code into service.pp

sudo touch service.pp

class mariadb::service {
service {
"mysql": ensure => running,
hasstatus => true,
hasrestart => true,
enable => true,
require => Class["mariadb::config"],
}
}

This class ensures that the MariaDB service is running

Paste this code into the init.pp file

sudo touch init.pp

class mariadb {
include mariadb::install,
mariadb::config,
mariadb::service
}

This class calls all the necessary components

Continued in ticket #204