Skip to content

Instantly share code, notes, and snippets.

@rkhatibi
Forked from maxmanders/databases.pp
Created June 10, 2012 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkhatibi/2906607 to your computer and use it in GitHub Desktop.
Save rkhatibi/2906607 to your computer and use it in GitHub Desktop.
define mysql::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"],
}
}
class mysql::databases {
mysql::createdb { "create-dev-db":
dbname => "specdit_dev",
user => "specdit",
password => "xxx",
}
mysql::createdb { "create-live-db":
dbname => "specdit_live",
user => "specdit",
password => "xxx",
}
mysql::createdb { "create-test-db":
dbname => "specdit_test",
user => "specdit",
password => "xxx",
}
mysql::createdb { "create-stage-db":
dbname => "specdit_stage",
user => "specdit",
password => "xxx",
}
}
class mysql {
include mysql::databases
# 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