You want to install MariaDB, create a database and a user account ? Ask Puppet to do this job …

“puppetlabs-mysql” module

First of all, you need “puppetlabs-mysql” module on your Puppet server, So you can install it :

[root@puppetserver ~]# puppet module install puppetlabs-mysql
Notice: Preparing to install into /etc/puppetlabs/code/environments/production/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppetlabs/code/environments/production/modules
+-- puppetlabs-mysql (v3.9.0)
  +-- puppet-staging (v2.0.1)
  +-- puppetlabs-stdlib (v4.12.0)

Your short Puppet manifest

Create an working directory :

[root@puppetserver ~]# mkdir /examples && cd /examples

And create this short manifest :

[root@puppetserver examples]# cat create_mariadb.pp
class create_mariadb {

  class { '::mysql::server':
    root_password    => 'here_is_my_maria_root_password',
    override_options => { 'mysqld' => { 'max_connections' => '512' } }
  }

  $my_database = 'my_base'
  $my_user = 'db_user'

  mysql::db { $my_database:
    user     => $my_user,
    password => 'here_is_my_user_password',
    grant    => [ 'SELECT' , 'INSERT' , 'UPDATE' , 'DELETE' , 'DROP' , 'CREATE' ,
                  'ALTER' , 'CREATE VIEW' , 'SHOW VIEW' , 'TRIGGER' , 'LOCK TABLES' ],
  }

  mysql_grant { "${my_user}@localhost/*.*":
    ensure     => 'present',
    table      => '*.*',
    options    => ['GRANT'],
    privileges => [ 'SUPER' , 'RELOAD' ],
    user       => "${my_user}@localhost",
  }

}

class { 'create_mariadb': }

Check the syntax :

[root@puppetserver examples]# puppet parser validate create_mariadb.pp

Now, execute your manifest :

[root@puppetserver examples]# puppet apply create_mariadb.pp
Notice: Compiled catalog for puppetserver.argonay.wou in environment production in 0.97 seconds
Notice: /Stage[main]/Mysql::Server::Install/Package[mysql-server]/ensure: created
Notice: /Stage[main]/Mysql::Server::Installdb/Mysql_datadir[/var/lib/mysql]/ensure: created
Notice: /Stage[main]/Mysql::Server::Service/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
Notice: /Stage[main]/Mysql::Server::Root_password/Mysql_user[root@localhost]/password_hash: defined 'password_hash' as '*0E278CA499FE538677893EF54DDB17810DAAFC68'
Notice: /Stage[main]/Mysql::Server::Root_password/File[/root/.my.cnf]/ensure: defined content as '{md5}163bf93fb258af7991e5769b9ee1a040'
Notice: /Stage[main]/Create_mariadb/Mysql::Db[my_base]/Mysql_database[my_base]/ensure: created
Notice: /Stage[main]/Create_mariadb/Mysql::Db[my_base]/Mysql_user[db_user@localhost]/ensure: created
Notice: /Stage[main]/Create_mariadb/Mysql_grant[db_user@localhost/*.*]/privileges: privileges changed ['USAGE'] to 'RELOAD SUPER'
Notice: /Stage[main]/Create_mariadb/Mysql_grant[db_user@localhost/*.*]/options: options changed ['NONE'] to 'GRANT'
Notice: /Stage[main]/Create_mariadb/Mysql::Db[my_base]/Mysql_grant[db_user@localhost/my_base.*]/ensure: created
Notice: Applied catalog in 120.84 seconds

What Puppet did ?

You got MariaDB installed :

[root@puppetserver examples]# rpm -qa | grep mariadb
mariadb-libs-5.5.50-1.el7_2.x86_64
mariadb-5.5.50-1.el7_2.x86_64
mariadb-server-5.5.50-1.el7_2.x86_64

The database has been created :

[root@puppetserver ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 5.5.50-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| my_base            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> quit
Bye

And the user has those privileges :

[root@puppetserver ~]# mysql -u db_user -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.50-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show grants for 'db_user'@'localhost';
+-------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for db_user@localhost                                                                                                                    |
+-------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT RELOAD, SUPER ON *.* TO 'db_user'@'localhost' IDENTIFIED BY PASSWORD '*4482E7A53EDFB8E648A3B06B076981DAF6BEC7AC' WITH GRANT OPTION        |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE VIEW, SHOW VIEW, TRIGGER ON `my_base`.* TO 'db_user'@'localhost' |
+-------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> quit
Bye

Exactly what we wanted !

 

en.pdf24.org    Send article as PDF   

Leave a Reply

Your email address will not be published. Required fields are marked *


*