From b1cb51e8643fd5b802665bef8f7f412c5f65b129 Mon Sep 17 00:00:00 2001 From: Yolanda Robla Date: Thu, 15 Oct 2015 11:27:56 +0200 Subject: [PATCH] Add mysql class to manage db, and configure db name When using local mysql, this class is useful to automate database creation. Also add the ability to configure database name, so it can match the name created on mysql class. Change-Id: I9c97b4a6355816b931e93d053f4748ef88f0a823 --- manifests/mysql.pp | 30 ++++++++++++++++++++++++++++++ manifests/site.pp | 1 + templates/manage.py.erb | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 manifests/mysql.pp diff --git a/manifests/mysql.pp b/manifests/mysql.pp new file mode 100644 index 0000000..0a28f9b --- /dev/null +++ b/manifests/mysql.pp @@ -0,0 +1,30 @@ +# == Class: puppet-lodgeit::mysql +# +class lodgeit::mysql( + $mysql_root_password, + $database_name = $name, + $database_user = $name, + $database_password, +) { + class { '::mysql::server': + config_hash => { + 'root_password' => $mysql_root_password, + 'default_engine' => 'InnoDB', + 'bind_address' => '127.0.0.1', + } + } + include ::mysql::server::account_security + + mysql::db { $database_name: + user => $database_user, + password => $database_password, + host => 'localhost', + grant => ['all'], + charset => 'utf8', + require => [ + Class['mysql::server'], + Class['mysql::server::account_security'], + ], + } +} + diff --git a/manifests/site.pp b/manifests/site.pp index c19ff5f..cfc5ba8 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -5,6 +5,7 @@ define lodgeit::site( $port, $db_password, $db_host='localhost', + $db_name=$name, $db_user=$name, $vhost_name="paste.${name}.org", $image=undef, diff --git a/templates/manage.py.erb b/templates/manage.py.erb index e57e024..81d7930 100644 --- a/templates/manage.py.erb +++ b/templates/manage.py.erb @@ -7,7 +7,7 @@ from lodgeit import local from lodgeit.application import make_app from lodgeit.database import session -dburi = 'mysql://<%= @db_user %>:<%= @db_password %>@<%= @db_host %>:3306/<%= @name %>' +dburi = 'mysql://<%= @db_user %>:<%= @db_password %>@<%= @db_host %>:3306/<%= @db_name %>' SECRET_KEY = 'no secret key'