summaryrefslogtreecommitdiff
path: root/manifests
diff options
context:
space:
mode:
Diffstat (limited to 'manifests')
-rw-r--r--manifests/default_database.pp45
1 files changed, 45 insertions, 0 deletions
diff --git a/manifests/default_database.pp b/manifests/default_database.pp
new file mode 100644
index 0000000..1c99af5
--- /dev/null
+++ b/manifests/default_database.pp
@@ -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,
+ }
+}