Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
add define to manage a common db/user setup
Browse files Browse the repository at this point in the history
a db and a corresponding user with all access to that database.
  • Loading branch information
duritong committed Jul 21, 2010
1 parent fd690bd commit 0357cca
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions manifests/default_database.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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(
$username = 'absent',
$password,
$password_is_encrypted = true,
$privileges = 'all',
$host = '127.0.0.1',
$ensure = 'present'
) {
$real_username = $username ? {
'absent' => $name,
default => $username
}
mysql_database{"$name":
ensure => $ensure
}
case $password {
'absent': {
info("we don't create the user for database: ${name}")
$grant_require = Mysql_database["$name"]
}
default: {
mysql_user{"${real_username}@${host}":
password_hash => $password_is_encrypted ? {
true => "$password",
default => mysql_password("$password")
},
ensure => $ensure,
require => [
Mysql_database["$name"]
],
}
$grant_require = [
Mysql_database["$name"],
Mysql_user["${real_username}@${host}"]
]
}
}
mysql_grant{"${real_username}@${host}/${name}":
privileges => "$privileges",
require => $grant_require,
}
}

0 comments on commit 0357cca

Please sign in to comment.