Skip to content

Instantly share code, notes, and snippets.

@eMerzh
Created December 16, 2012 12:13
Show Gist options
  • Save eMerzh/4306706 to your computer and use it in GitHub Desktop.
Save eMerzh/4306706 to your computer and use it in GitHub Desktop.
define postgresql::db ($name, $ensure=present){
case $ensure {
present: {
exec { "Create $name postgres db":
command => "createdb $name",
unless => "test \$(psql -tA -c \"SELECT count(*)=1 FROM pg_catalog.pg_database where datname='${name}';\") = t",
}
}
absent: {
exec { "Remove $name postgres db":
command => "dropdb $name",
user => "postgres",
onlyif => "test \$(psql -tA -c \"SELECT count(*)=1 FROM pg_catalog.pg_database where datname='${name}';\") = t",
}
}
default: {
fail "Invalid 'ensure' value '$ensure' for postgres::database"
}
}
}
#lib/store.pp
define postgresql::lib::hstore($db_name) {
exec {"pg_installlib_hstore_${cluster_name}_${db}":
user => "postgres",
command => "psql -f /usr/share/postgresql/hstore.sql ${db_name} ",
unless => "psql -tA -c \"SELECT ''::hstore;\" ${db_name}",
require => Postgresql::Db["${db_name}"],
}
}
#lib/trgm.pp
define postgresql::lib::trgm($db_name) {
exec {"pg_installlib_trgm_${cluster_name}_${db}":
user => "postgres",
command => "psql -f /usr/share/postgresql/trgm.sql ${db_name} ",
unless => "psql -tA -c \"SELECT show_limit();\" ${db_name}",
require => Postgresql::Db["${db_name}"],
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment