cleaned up style a little:
- updated mysql::ruby to use params value for package_name - updated server to use params value for service and package - clarified some param names to make them more consistent
This commit is contained in:
parent
f65e49e2ce
commit
0b5cc21348
8 changed files with 56 additions and 34 deletions
|
@ -4,31 +4,39 @@
|
||||||
# db_user
|
# db_user
|
||||||
# db_pw
|
# db_pw
|
||||||
#
|
#
|
||||||
define mysql::db ( $db_user, $db_pw, $db_charset = 'utf8', $host = 'localhost', $grant='all', $sql='') {
|
define mysql::db (
|
||||||
|
$user,
|
||||||
|
$password,
|
||||||
|
$charset = 'utf8',
|
||||||
|
$host = 'localhost',
|
||||||
|
$grant='all',
|
||||||
|
$sql=''
|
||||||
|
) {
|
||||||
#
|
#
|
||||||
|
notice($user)
|
||||||
database { $name:
|
database { $name:
|
||||||
ensure => present,
|
ensure => present,
|
||||||
charset => $db_charset,
|
charset => $charset,
|
||||||
provider => 'mysql',
|
provider => 'mysql',
|
||||||
require => Class['mysql::server']
|
require => Class['mysql::server']
|
||||||
}
|
}
|
||||||
database_user{"${db_user}@${host}":
|
database_user{"${user}@${host}":
|
||||||
ensure => present,
|
ensure => present,
|
||||||
password_hash => mysql_password($db_pw),
|
password_hash => mysql_password($password),
|
||||||
provider => 'mysql',
|
provider => 'mysql',
|
||||||
require => Database[$name],
|
require => Database[$name],
|
||||||
}
|
}
|
||||||
database_grant{"${db_user}@${host}/${name}":
|
database_grant{"${user}@${host}/${name}":
|
||||||
# privileges => [ 'alter_priv', 'insert_priv', 'select_priv', 'update_priv' ],
|
# privileges => [ 'alter_priv', 'insert_priv', 'select_priv', 'update_priv' ],
|
||||||
privileges => $grant,
|
privileges => $grant,
|
||||||
provider => 'mysql',
|
provider => 'mysql',
|
||||||
require => Database_user["${db_user}@${host}"],
|
require => Database_user["${user}@${host}"],
|
||||||
}
|
}
|
||||||
if($sql) {
|
if($sql) {
|
||||||
exec{"${name}-import-import":
|
exec{"${name}-import-import":
|
||||||
command => "/usr/bin/mysql -u ${db_user} -p${db_pw} -h ${host} ${name} < ${sql}",
|
command => "/usr/bin/mysql -u ${user} -p${password} -h ${host} ${name} < ${sql}",
|
||||||
logoutput => true,
|
logoutput => true,
|
||||||
require => Database_grant["${db_user}@${host}/${name}"],
|
require => Database_grant["${user}@${host}/${name}"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
class mysql::params{
|
class mysql::params{
|
||||||
$socket = '/var/run/mysqld/mysqld.sock'
|
$socket = '/var/run/mysqld/mysqld.sock'
|
||||||
|
case $operatingsystem {
|
||||||
|
'centos', 'redhat', 'fedora': {
|
||||||
|
$service_name = 'mysqld'
|
||||||
|
}
|
||||||
|
'ubuntu', 'debian': {
|
||||||
|
$service_name = 'mysql'
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
$python_package_name = 'python-mysqldb'
|
||||||
|
$ruby_package_name = 'ruby-mysql'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#installs the ruby bindings for mysql
|
#installs the ruby bindings for mysql
|
||||||
class mysql::ruby {
|
class mysql::ruby(
|
||||||
|
$package_name = $mysql::params::ruby_package_name
|
||||||
|
) inherits mysql::params {
|
||||||
# I am not making the mysql package a dep for this
|
# I am not making the mysql package a dep for this
|
||||||
# the only dep is the package which yum will resolve for me.
|
# the only dep is the package which yum will resolve for me.
|
||||||
#case $operatingsystem {
|
#case $operatingsystem {
|
||||||
|
@ -9,6 +11,7 @@ class mysql::ruby {
|
||||||
|
|
||||||
package{'ruby-mysql':
|
package{'ruby-mysql':
|
||||||
# name => $ruby_mysql_name,
|
# name => $ruby_mysql_name,
|
||||||
|
name => $package_name,
|
||||||
provider => 'gem',
|
provider => 'gem',
|
||||||
ensure => installed,
|
ensure => installed,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
# installs mysql
|
# installs mysql
|
||||||
class mysql::server(
|
class mysql::server(
|
||||||
$mysql_root_pw,
|
$root_password,
|
||||||
$mysql_old_pw = ''
|
$old_root_password = '',
|
||||||
) {
|
$service_name = $mysql::params::service_name,
|
||||||
|
$package_name = 'mysql-server'
|
||||||
|
) inherits mysql::params {
|
||||||
package{'mysql-server':
|
package{'mysql-server':
|
||||||
name => 'mysql-server',
|
name => $package_name,
|
||||||
ensure => installed,
|
ensure => present,
|
||||||
notify => Service['mysqld'],
|
notify => Service['mysqld'],
|
||||||
}
|
}
|
||||||
service { 'mysqld':
|
service { 'mysqld':
|
||||||
name => $operatingsystem?{
|
name => $service_name,
|
||||||
ubuntu => 'mysql',
|
|
||||||
debian => 'mysql',
|
|
||||||
default => 'mysqld',
|
|
||||||
},
|
|
||||||
ensure => running,
|
ensure => running,
|
||||||
enable => true,
|
enable => true,
|
||||||
}
|
}
|
||||||
|
@ -21,7 +19,7 @@ class mysql::server(
|
||||||
# the reason is that I need the service to be started before mods to the config
|
# the reason is that I need the service to be started before mods to the config
|
||||||
# file which can cause a refresh
|
# file which can cause a refresh
|
||||||
exec{ 'mysqld-restart':
|
exec{ 'mysqld-restart':
|
||||||
command => '/usr/sbin/service mysqld restart',
|
command => "/usr/sbin/service ${service_name} restart",
|
||||||
refreshonly => true,
|
refreshonly => true,
|
||||||
}
|
}
|
||||||
File{
|
File{
|
||||||
|
@ -30,15 +28,15 @@ class mysql::server(
|
||||||
require => Package['mysql-server'],
|
require => Package['mysql-server'],
|
||||||
}
|
}
|
||||||
# use the previous password for the case where its not configured in /root/.my.cnf
|
# use the previous password for the case where its not configured in /root/.my.cnf
|
||||||
case $mysql_old_pw {
|
case $old_root_password {
|
||||||
'': {$old_pw=''}
|
'': {$old_pw=''}
|
||||||
default: {$old_pw="-p${mysql_old_pw}"}
|
default: {$old_pw="-p${old_root_password}"}
|
||||||
}
|
}
|
||||||
exec{ 'set_mysql_rootpw':
|
exec{ 'set_mysql_rootpw':
|
||||||
command => "mysqladmin -u root ${old_pw} password ${mysql_root_pw}",
|
command => "mysqladmin -u root ${old_pw} password ${root_password}",
|
||||||
#logoutput => on_failure,
|
#logoutput => on_failure,
|
||||||
logoutput => true,
|
logoutput => true,
|
||||||
unless => "mysqladmin -u root -p${mysql_root_pw} status > /dev/null",
|
unless => "mysqladmin -u root -p${root_password} status > /dev/null",
|
||||||
path => '/usr/local/sbin:/usr/bin',
|
path => '/usr/local/sbin:/usr/bin',
|
||||||
require => [Package['mysql-server'], Service['mysqld']],
|
require => [Package['mysql-server'], Service['mysqld']],
|
||||||
before => File['/root/.my.cnf'],
|
before => File['/root/.my.cnf'],
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[client]
|
[client]
|
||||||
user=root
|
user=root
|
||||||
host=localhost
|
host=localhost
|
||||||
password=<%= mysql_root_pw -%>
|
password=<%= root_password -%>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
$mysql_root_pw='password'
|
class { 'mysql::server':
|
||||||
include mysql::server
|
root_password => 'password',
|
||||||
|
}
|
||||||
database{['test1', 'test2', 'test3']:
|
database{['test1', 'test2', 'test3']:
|
||||||
ensure => present,
|
ensure => present,
|
||||||
charset => 'utf8',
|
charset => 'utf8',
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
$mysql_root_pw='password'
|
$mysql_root_pw='password'
|
||||||
include mysql::server
|
class { 'mysql::server':
|
||||||
|
root_password => 'password',
|
||||||
|
}
|
||||||
#database_user{['test1@localhost', 'test2@localhost', 'test3@localhost']:
|
#database_user{['test1@localhost', 'test2@localhost', 'test3@localhost']:
|
||||||
database_user{'redmine@localhost':
|
database_user{'redmine@localhost':
|
||||||
# ensure => absent,
|
# ensure => absent,
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#
|
|
||||||
# I need a way to specify the old password,
|
|
||||||
# is the old password is specified and not set in the
|
|
||||||
# .my.cnf file, then we are hosed
|
|
||||||
#$mysql_old_pw='password2'
|
#$mysql_old_pw='password2'
|
||||||
$mysql_root_pw='password'
|
class { 'mysql::server':
|
||||||
include mysql::server
|
root_password => 'password',
|
||||||
|
#old_root_password => 'foo'
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue