Skip to content

Commit 0b5cc21

Browse files
author
Dan Bode
committed
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
1 parent f65e49e commit 0b5cc21

File tree

8 files changed

+56
-34
lines changed

8 files changed

+56
-34
lines changed

manifests/db.pp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,39 @@
44
# db_user
55
# db_pw
66
#
7-
define mysql::db ( $db_user, $db_pw, $db_charset = 'utf8', $host = 'localhost', $grant='all', $sql='') {
7+
define mysql::db (
8+
$user,
9+
$password,
10+
$charset = 'utf8',
11+
$host = 'localhost',
12+
$grant='all',
13+
$sql=''
14+
) {
815
#
16+
notice($user)
917
database { $name:
1018
ensure => present,
11-
charset => $db_charset,
19+
charset => $charset,
1220
provider => 'mysql',
1321
require => Class['mysql::server']
1422
}
15-
database_user{"${db_user}@${host}":
23+
database_user{"${user}@${host}":
1624
ensure => present,
17-
password_hash => mysql_password($db_pw),
25+
password_hash => mysql_password($password),
1826
provider => 'mysql',
1927
require => Database[$name],
2028
}
21-
database_grant{"${db_user}@${host}/${name}":
29+
database_grant{"${user}@${host}/${name}":
2230
# privileges => [ 'alter_priv', 'insert_priv', 'select_priv', 'update_priv' ],
2331
privileges => $grant,
2432
provider => 'mysql',
25-
require => Database_user["${db_user}@${host}"],
33+
require => Database_user["${user}@${host}"],
2634
}
2735
if($sql) {
2836
exec{"${name}-import-import":
29-
command => "/usr/bin/mysql -u ${db_user} -p${db_pw} -h ${host} ${name} < ${sql}",
37+
command => "/usr/bin/mysql -u ${user} -p${password} -h ${host} ${name} < ${sql}",
3038
logoutput => true,
31-
require => Database_grant["${db_user}@${host}/${name}"],
39+
require => Database_grant["${user}@${host}/${name}"],
3240
}
3341
}
3442
}

manifests/params.pp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
class mysql::params{
22
$socket = '/var/run/mysqld/mysqld.sock'
3+
case $operatingsystem {
4+
'centos', 'redhat', 'fedora': {
5+
$service_name = 'mysqld'
6+
}
7+
'ubuntu', 'debian': {
8+
$service_name = 'mysql'
9+
}
10+
default: {
11+
$python_package_name = 'python-mysqldb'
12+
$ruby_package_name = 'ruby-mysql'
13+
}
14+
}
315
}

manifests/ruby.pp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#installs the ruby bindings for mysql
2-
class mysql::ruby {
2+
class mysql::ruby(
3+
$package_name = $mysql::params::ruby_package_name
4+
) inherits mysql::params {
35
# I am not making the mysql package a dep for this
46
# the only dep is the package which yum will resolve for me.
57
#case $operatingsystem {
@@ -9,6 +11,7 @@
911

1012
package{'ruby-mysql':
1113
# name => $ruby_mysql_name,
14+
name => $package_name,
1215
provider => 'gem',
1316
ensure => installed,
1417
}

manifests/server.pp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
# installs mysql
22
class mysql::server(
3-
$mysql_root_pw,
4-
$mysql_old_pw = ''
5-
) {
3+
$root_password,
4+
$old_root_password = '',
5+
$service_name = $mysql::params::service_name,
6+
$package_name = 'mysql-server'
7+
) inherits mysql::params {
68
package{'mysql-server':
7-
name => 'mysql-server',
8-
ensure => installed,
9+
name => $package_name,
10+
ensure => present,
911
notify => Service['mysqld'],
1012
}
1113
service { 'mysqld':
12-
name => $operatingsystem?{
13-
ubuntu => 'mysql',
14-
debian => 'mysql',
15-
default => 'mysqld',
16-
},
14+
name => $service_name,
1715
ensure => running,
1816
enable => true,
1917
}
2018
# this kind of sucks, that I have to specify a difference resource for restart.
2119
# the reason is that I need the service to be started before mods to the config
2220
# file which can cause a refresh
2321
exec{ 'mysqld-restart':
24-
command => '/usr/sbin/service mysqld restart',
22+
command => "/usr/sbin/service ${service_name} restart",
2523
refreshonly => true,
2624
}
2725
File{
@@ -30,15 +28,15 @@
3028
require => Package['mysql-server'],
3129
}
3230
# use the previous password for the case where its not configured in /root/.my.cnf
33-
case $mysql_old_pw {
31+
case $old_root_password {
3432
'': {$old_pw=''}
35-
default: {$old_pw="-p${mysql_old_pw}"}
33+
default: {$old_pw="-p${old_root_password}"}
3634
}
3735
exec{ 'set_mysql_rootpw':
38-
command => "mysqladmin -u root ${old_pw} password ${mysql_root_pw}",
36+
command => "mysqladmin -u root ${old_pw} password ${root_password}",
3937
#logoutput => on_failure,
4038
logoutput => true,
41-
unless => "mysqladmin -u root -p${mysql_root_pw} status > /dev/null",
39+
unless => "mysqladmin -u root -p${root_password} status > /dev/null",
4240
path => '/usr/local/sbin:/usr/bin',
4341
require => [Package['mysql-server'], Service['mysqld']],
4442
before => File['/root/.my.cnf'],

templates/my.cnf.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[client]
22
user=root
33
host=localhost
4-
password=<%= mysql_root_pw -%>
4+
password=<%= root_password -%>

tests/mysql_database.pp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
$mysql_root_pw='password'
2-
include mysql::server
1+
class { 'mysql::server':
2+
root_password => 'password',
3+
}
34
database{['test1', 'test2', 'test3']:
45
ensure => present,
56
charset => 'utf8',

tests/mysql_user.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
$mysql_root_pw='password'
2-
include mysql::server
2+
class { 'mysql::server':
3+
root_password => 'password',
4+
}
35
#database_user{['test1@localhost', 'test2@localhost', 'test3@localhost']:
46
database_user{'redmine@localhost':
57
# ensure => absent,

tests/server.pp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#
2-
# I need a way to specify the old password,
3-
# is the old password is specified and not set in the
4-
# .my.cnf file, then we are hosed
51
#$mysql_old_pw='password2'
6-
$mysql_root_pw='password'
7-
include mysql::server
2+
class { 'mysql::server':
3+
root_password => 'password',
4+
#old_root_password => 'foo'
5+
}

0 commit comments

Comments
 (0)