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:
Dan Bode 2011-05-26 18:11:24 -07:00
parent f65e49e2ce
commit 0b5cc21348
8 changed files with 56 additions and 34 deletions

View file

@ -4,31 +4,39 @@
# db_user
# 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:
ensure => present,
charset => $db_charset,
charset => $charset,
provider => 'mysql',
require => Class['mysql::server']
}
database_user{"${db_user}@${host}":
database_user{"${user}@${host}":
ensure => present,
password_hash => mysql_password($db_pw),
password_hash => mysql_password($password),
provider => 'mysql',
require => Database[$name],
}
database_grant{"${db_user}@${host}/${name}":
database_grant{"${user}@${host}/${name}":
# privileges => [ 'alter_priv', 'insert_priv', 'select_priv', 'update_priv' ],
privileges => $grant,
provider => 'mysql',
require => Database_user["${db_user}@${host}"],
require => Database_user["${user}@${host}"],
}
if($sql) {
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,
require => Database_grant["${db_user}@${host}/${name}"],
require => Database_grant["${user}@${host}/${name}"],
}
}
}

View file

@ -1,3 +1,15 @@
class mysql::params{
$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'
}
}
}

View file

@ -1,5 +1,7 @@
#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
# the only dep is the package which yum will resolve for me.
#case $operatingsystem {
@ -9,6 +11,7 @@ class mysql::ruby {
package{'ruby-mysql':
# name => $ruby_mysql_name,
name => $package_name,
provider => 'gem',
ensure => installed,
}

View file

@ -1,19 +1,17 @@
# installs mysql
class mysql::server(
$mysql_root_pw,
$mysql_old_pw = ''
) {
$root_password,
$old_root_password = '',
$service_name = $mysql::params::service_name,
$package_name = 'mysql-server'
) inherits mysql::params {
package{'mysql-server':
name => 'mysql-server',
ensure => installed,
name => $package_name,
ensure => present,
notify => Service['mysqld'],
}
service { 'mysqld':
name => $operatingsystem?{
ubuntu => 'mysql',
debian => 'mysql',
default => 'mysqld',
},
name => $service_name,
ensure => running,
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
# file which can cause a refresh
exec{ 'mysqld-restart':
command => '/usr/sbin/service mysqld restart',
command => "/usr/sbin/service ${service_name} restart",
refreshonly => true,
}
File{
@ -30,15 +28,15 @@ class mysql::server(
require => Package['mysql-server'],
}
# 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=''}
default: {$old_pw="-p${mysql_old_pw}"}
default: {$old_pw="-p${old_root_password}"}
}
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 => 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',
require => [Package['mysql-server'], Service['mysqld']],
before => File['/root/.my.cnf'],

View file

@ -1,4 +1,4 @@
[client]
user=root
host=localhost
password=<%= mysql_root_pw -%>
password=<%= root_password -%>

View file

@ -1,5 +1,6 @@
$mysql_root_pw='password'
include mysql::server
class { 'mysql::server':
root_password => 'password',
}
database{['test1', 'test2', 'test3']:
ensure => present,
charset => 'utf8',

View file

@ -1,5 +1,7 @@
$mysql_root_pw='password'
include mysql::server
class { 'mysql::server':
root_password => 'password',
}
#database_user{['test1@localhost', 'test2@localhost', 'test3@localhost']:
database_user{'redmine@localhost':
# ensure => absent,

View file

@ -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_root_pw='password'
include mysql::server
class { 'mysql::server':
root_password => 'password',
#old_root_password => 'foo'
}