Skip to content

Instantly share code, notes, and snippets.

@maxmanders
Created June 10, 2012 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maxmanders/2906595 to your computer and use it in GitHub Desktop.
Save maxmanders/2906595 to your computer and use it in GitHub Desktop.
class mysql::databases {
# Helper resource to create databases and associated grants.
define createdb {
exec { "create-${name}-db":
unless => "mysql -uroot -p${config::mysqlRootPassword} ${name}",
command => "mysql -uroot -p${config::mysqlRootPassword} -e \"create database ${name}; grant all on ${name}.* to ${config::dbUser}@localhost identified by '${config::dbPassword}';\"",
require => Service["mysql"],
}
}
mysql::databases::createdb { "create-dev-db":
dbname => "specdit_dev",
user => "specdit",
password => "xxx",
}
mysql::databases::createdb { "create-live-db":
dbname => "specdit_live",
user => "specdit",
password => "xxx",
}
mysql::databases::createdb { "create-test-db":
dbname => "specdit_test",
user => "specdit",
password => "xxx",
}
mysql::databases::createdb { "create-stage-db":
dbname => "specdit_stage",
user => "specdit",
password => "xxx",
}
}
class mysql {
# Makee sure MySQL is installed.
package { "mysql-server":
ensure => present,
require => Exec["apt-get update"]
}
# Make sure MySQL is started.
service { "mysql":
ensure => running,
require => Package["mysql-server"],
}
# Set default MySQL root user password.
exec { "set-mysql-passwrod":
unless => "mysqladmin -uroot -p${config::mysqlRootPassword} status",
command => "mysqladmin -uroot password ${config::mysqlRootPassword}",
require => Service["mysql"],
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment