2010-07-21 07:05:37 +02:00
|
|
|
# create default database
|
|
|
|
# generate hashed password with:
|
|
|
|
# ruby -r'digest/sha1' -e 'puts "*" + Digest::SHA1.hexdigest(Digest::SHA1.digest(ARGV[0])).upcase' PASSWORD
|
|
|
|
define mysql::default_database(
|
2011-02-14 19:30:18 +01:00
|
|
|
$username = 'absent',
|
|
|
|
$password = 'absent',
|
|
|
|
$password_is_encrypted = true,
|
|
|
|
$privileges = 'all',
|
|
|
|
$host = '127.0.0.1',
|
|
|
|
$ensure = 'present'
|
2010-07-21 07:05:37 +02:00
|
|
|
) {
|
2011-02-14 19:30:18 +01:00
|
|
|
$real_username = $username ? {
|
|
|
|
'absent' => $name,
|
|
|
|
default => $username
|
|
|
|
}
|
|
|
|
mysql_database{"$name":
|
|
|
|
ensure => $ensure
|
|
|
|
}
|
|
|
|
if $password == 'absent' and $ensure != 'absent' {
|
|
|
|
info("we don't create the user for database: ${name}")
|
|
|
|
$grant_require = Mysql_database["$name"]
|
|
|
|
} else {
|
|
|
|
mysql_user{"${real_username}@${host}":
|
|
|
|
ensure => $ensure,
|
|
|
|
require => [
|
|
|
|
Mysql_database["$name"]
|
|
|
|
],
|
2010-07-21 07:05:37 +02:00
|
|
|
}
|
2011-02-14 19:30:18 +01:00
|
|
|
$grant_require = [
|
|
|
|
Mysql_database["$name"],
|
|
|
|
Mysql_user["${real_username}@${host}"]
|
|
|
|
]
|
|
|
|
if $ensure == 'present' {
|
|
|
|
Mysql_user["${real_username}@${host}"]{
|
|
|
|
password_hash => $password_is_encrypted ? {
|
|
|
|
true => "$password",
|
|
|
|
default => mysql_password("$password")
|
|
|
|
},
|
|
|
|
}
|
2010-07-21 07:05:37 +02:00
|
|
|
}
|
2011-02-14 19:30:18 +01:00
|
|
|
}
|
|
|
|
if $ensure == 'present' {
|
2010-07-21 07:05:37 +02:00
|
|
|
mysql_grant{"${real_username}@${host}/${name}":
|
2011-02-14 19:30:18 +01:00
|
|
|
privileges => "$privileges",
|
|
|
|
require => $grant_require,
|
2010-07-21 07:05:37 +02:00
|
|
|
}
|
2011-02-14 19:30:18 +01:00
|
|
|
}
|
2010-07-21 07:05:37 +02:00
|
|
|
}
|