Merge pull request #138 from kbarber/ticket/master/128-provide_more_custom_parameters_for_custom_packaging
Ticket/master/128 provide more custom parameters for custom packaging
This commit is contained in:
commit
673e47ee94
15 changed files with 299 additions and 127 deletions
33
README.md
33
README.md
|
@ -164,6 +164,39 @@ This will set the default database locale for all databases created with this mo
|
||||||
####`charset`
|
####`charset`
|
||||||
This will set the default charset for all databases created with this module. On certain operating systems this will be used during the `template1` initialization as well so it becomes a default outside of the module as well. Defaults to `UTF8`.
|
This will set the default charset for all databases created with this module. On certain operating systems this will be used during the `template1` initialization as well so it becomes a default outside of the module as well. Defaults to `UTF8`.
|
||||||
|
|
||||||
|
####`datadir`
|
||||||
|
This setting can be used to override the default postgresql data directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro.
|
||||||
|
|
||||||
|
####`confdir`
|
||||||
|
This setting can be used to override the default postgresql configuration directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro.
|
||||||
|
|
||||||
|
####`bindir`
|
||||||
|
This setting can be used to override the default postgresql binaries directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro.
|
||||||
|
|
||||||
|
####`client_package_name`
|
||||||
|
This setting can be used to override the default postgresql client package name. If not specified, the module will use whatever package name is the default for your OS distro.
|
||||||
|
|
||||||
|
####`server_package_name`
|
||||||
|
This setting can be used to override the default postgresql server package name. If not specified, the module will use whatever package name is the default for your OS distro.
|
||||||
|
|
||||||
|
####`devel_package_name`
|
||||||
|
This setting can be used to override the default postgresql devel package name. If not specified, the module will use whatever package name is the default for your OS distro.
|
||||||
|
|
||||||
|
####`java_package_name`
|
||||||
|
This setting can be used to override the default postgresql java package name. If not specified, the module will use whatever package name is the default for your OS distro.
|
||||||
|
|
||||||
|
####`service_name`
|
||||||
|
This setting can be used to override the default postgresql service name. If not specified, the module will use whatever service name is the default for your OS distro.
|
||||||
|
|
||||||
|
####`user`
|
||||||
|
This setting can be used to override the default postgresql super user and owner of postgresql related files in the file system. If not specified, the module will use the user name 'postgres'.
|
||||||
|
|
||||||
|
####`group`
|
||||||
|
This setting can be used to override the default postgresql user group to be used for related files in the file system. If not specified, the module will use the group name 'postgres'.
|
||||||
|
|
||||||
|
####`run_initdb`
|
||||||
|
This setting can be used to explicitly call the initdb operation after server package is installed and before the postgresql service is started. If not specified, the module will decide whether to call initdb or not depending on your OS distro.
|
||||||
|
|
||||||
###Class: postgresql::server
|
###Class: postgresql::server
|
||||||
Here are the options that you can set in the `config_hash` parameter of `postgresql::server`:
|
Here are the options that you can set in the `config_hash` parameter of `postgresql::server`:
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,8 @@ Puppet::Type.type(:postgresql_psql).provide(:ruby) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_sql_command(sql)
|
def run_sql_command(sql)
|
||||||
command = %{psql #{"-d #{resource[:db]}" if resource[:db]} -t -c "#{sql.gsub('"', '\"')}"}
|
command = %{#{resource[:psql_path]} #{"-d #{resource[:db]}" if resource[:db]} -t -c "#{sql.gsub('"', '\"')}"}
|
||||||
|
|
||||||
if resource[:cwd]
|
if resource[:cwd]
|
||||||
Dir.chdir resource[:cwd] do
|
Dir.chdir resource[:cwd] do
|
||||||
Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group])
|
Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group])
|
||||||
|
|
|
@ -49,6 +49,11 @@ Puppet::Type.newtype(:postgresql_psql) do
|
||||||
desc "The name of the database to execute the SQL command against."
|
desc "The name of the database to execute the SQL command against."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
newparam(:psql_path) do
|
||||||
|
desc "The path to psql executable."
|
||||||
|
defaultto("psql")
|
||||||
|
end
|
||||||
|
|
||||||
newparam(:psql_user) do
|
newparam(:psql_user) do
|
||||||
desc "The system user account under which the psql command should be executed."
|
desc "The system user account under which the psql command should be executed."
|
||||||
defaultto("postgres")
|
defaultto("postgres")
|
||||||
|
|
|
@ -28,7 +28,7 @@ class postgresql::config::afterservice(
|
||||||
# for pg_hba.conf.
|
# for pg_hba.conf.
|
||||||
exec { 'set_postgres_postgrespw':
|
exec { 'set_postgres_postgrespw':
|
||||||
# This command works w/no password because we run it as postgres system user
|
# This command works w/no password because we run it as postgres system user
|
||||||
command => "psql -c \"ALTER ROLE postgres PASSWORD '${postgres_password}'\"",
|
command => "psql -c \"ALTER ROLE ${postgresql::params::user} PASSWORD '${postgres_password}'\"",
|
||||||
user => $postgresql::params::user,
|
user => $postgresql::params::user,
|
||||||
group => $postgresql::params::group,
|
group => $postgresql::params::group,
|
||||||
logoutput => true,
|
logoutput => true,
|
||||||
|
|
|
@ -27,6 +27,13 @@ define postgresql::database(
|
||||||
) {
|
) {
|
||||||
include postgresql::params
|
include postgresql::params
|
||||||
|
|
||||||
|
# Set the defaults for the postgresql_psql resource
|
||||||
|
Postgresql_psql {
|
||||||
|
psql_user => $postgresql::params::user,
|
||||||
|
psql_group => $postgresql::params::group,
|
||||||
|
psql_path => $postgresql::params::psql_path,
|
||||||
|
}
|
||||||
|
|
||||||
# Optionally set the locale switch. Older versions of createdb may not accept
|
# Optionally set the locale switch. Older versions of createdb may not accept
|
||||||
# --locale, so if the parameter is undefined its safer not to pass it.
|
# --locale, so if the parameter is undefined its safer not to pass it.
|
||||||
if ($postgresql::params::version != '8.1') {
|
if ($postgresql::params::version != '8.1') {
|
||||||
|
@ -52,23 +59,20 @@ define postgresql::database(
|
||||||
postgresql_psql { "Check for existence of db '${dbname}'":
|
postgresql_psql { "Check for existence of db '${dbname}'":
|
||||||
command => 'SELECT 1',
|
command => 'SELECT 1',
|
||||||
unless => "SELECT datname FROM pg_database WHERE datname='${dbname}'",
|
unless => "SELECT datname FROM pg_database WHERE datname='${dbname}'",
|
||||||
cwd => $postgresql::params::datadir,
|
|
||||||
require => Class['postgresql::server']
|
require => Class['postgresql::server']
|
||||||
} ~>
|
} ~>
|
||||||
|
|
||||||
exec { $createdb_command :
|
exec { $createdb_command :
|
||||||
refreshonly => true,
|
refreshonly => true,
|
||||||
user => 'postgres',
|
user => $postgresql::params::user,
|
||||||
cwd => $postgresql::params::datadir,
|
|
||||||
logoutput => on_failure,
|
logoutput => on_failure,
|
||||||
} ~>
|
} ~>
|
||||||
|
|
||||||
# This will prevent users from connecting to the database unless they've been
|
# This will prevent users from connecting to the database unless they've been
|
||||||
# granted privileges.
|
# granted privileges.
|
||||||
postgresql_psql {"REVOKE ${public_revoke_privilege} ON DATABASE ${dbname} FROM public":
|
postgresql_psql {"REVOKE ${public_revoke_privilege} ON DATABASE \"${dbname}\" FROM public":
|
||||||
db => 'postgres',
|
db => $postgresql::params::user,
|
||||||
refreshonly => true,
|
refreshonly => true,
|
||||||
cwd => $postgresql::params::datadir,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,17 @@ define postgresql::database_grant(
|
||||||
$privilege,
|
$privilege,
|
||||||
$db,
|
$db,
|
||||||
$role,
|
$role,
|
||||||
$psql_db = 'postgres',
|
$psql_db = $postgresql::params::user,
|
||||||
$psql_user ='postgres'
|
$psql_user = $postgresql::params::user
|
||||||
) {
|
) {
|
||||||
include postgresql::params
|
include postgresql::params
|
||||||
|
|
||||||
|
Postgresql_psql {
|
||||||
|
psql_user => $postgresql::params::user,
|
||||||
|
psql_group => $postgresql::params::group,
|
||||||
|
psql_path => $postgresql::params::psql_path,
|
||||||
|
}
|
||||||
|
|
||||||
# TODO: FIXME: only works on databases, due to using has_database_privilege
|
# TODO: FIXME: only works on databases, due to using has_database_privilege
|
||||||
|
|
||||||
# TODO: this is a terrible hack; if they pass "ALL" as the desired privilege,
|
# TODO: this is a terrible hack; if they pass "ALL" as the desired privilege,
|
||||||
|
@ -50,11 +56,9 @@ define postgresql::database_grant(
|
||||||
default => $privilege,
|
default => $privilege,
|
||||||
}
|
}
|
||||||
|
|
||||||
postgresql_psql {"GRANT ${privilege} ON database ${db} TO ${role}":
|
postgresql_psql {"GRANT ${privilege} ON database \"${db}\" TO \"${role}\"":
|
||||||
db => $psql_db,
|
db => $psql_db,
|
||||||
psql_user => $psql_user,
|
psql_user => $psql_user,
|
||||||
unless => "SELECT 1 WHERE has_database_privilege('${role}', '${db}', '${unless_privilege}')",
|
unless => "SELECT 1 WHERE has_database_privilege('${role}', '${db}', '${unless_privilege}')",
|
||||||
cwd => $postgresql::params::datadir,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ define postgresql::database_user(
|
||||||
$password_hash,
|
$password_hash,
|
||||||
$createdb = false,
|
$createdb = false,
|
||||||
$createrole = false,
|
$createrole = false,
|
||||||
$db = 'postgres',
|
$db = $postgresql::params::user,
|
||||||
$superuser = false,
|
$superuser = false,
|
||||||
$user = $title
|
$user = $title
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
# For examples, see the files in the `tests` directory; in particular,
|
# For examples, see the files in the `tests` directory; in particular,
|
||||||
# `/server-yum-postgresql-org.pp`.
|
# `/server-yum-postgresql-org.pp`.
|
||||||
#
|
#
|
||||||
|
# === Parameters
|
||||||
#
|
#
|
||||||
# [*version*]
|
# [*version*]
|
||||||
# The postgresql version to install. If not specified, the
|
# The postgresql version to install. If not specified, the
|
||||||
|
@ -26,15 +27,70 @@
|
||||||
# set to `true`. It determines which package repository should
|
# set to `true`. It determines which package repository should
|
||||||
# be used to install the postgres packages. Currently supported
|
# be used to install the postgres packages. Currently supported
|
||||||
# values include `yum.postgresql.org`.
|
# values include `yum.postgresql.org`.
|
||||||
#
|
|
||||||
# [*locale*]
|
# [*locale*]
|
||||||
# This setting defines the default locale for initdb and createdb
|
# This setting defines the default locale for initdb and createdb
|
||||||
# commands. This default to 'undef' which is effectively 'C'.
|
# commands. This default to 'undef' which is effectively 'C'.
|
||||||
# [*charset*]
|
# [*charset*]
|
||||||
# Sets the default charset to be used for initdb and createdb.
|
# Sets the default charset to be used for initdb and createdb.
|
||||||
# Defaults to 'UTF8'.
|
# Defaults to 'UTF8'.
|
||||||
|
# [*datadir*]
|
||||||
|
# This setting can be used to override the default postgresql
|
||||||
|
# data directory for the target platform. If not specified, the
|
||||||
|
# module will use whatever directory is the default for your
|
||||||
|
# OS distro.
|
||||||
|
# [*confdir*]
|
||||||
|
# This setting can be used to override the default postgresql
|
||||||
|
# configuration directory for the target platform. If not
|
||||||
|
# specified, the module will use whatever directory is the
|
||||||
|
# default for your OS distro.
|
||||||
|
# [*bindir*]
|
||||||
|
# This setting can be used to override the default postgresql
|
||||||
|
# binaries directory for the target platform. If not
|
||||||
|
# specified, the module will use whatever directory is the
|
||||||
|
# default for your OS distro.
|
||||||
|
# [*client_package_name*]
|
||||||
|
# This setting can be used to override the default
|
||||||
|
# postgresql client package name. If not specified, the module
|
||||||
|
# will use whatever package name is the default for your
|
||||||
|
# OS distro.
|
||||||
|
# [*server_package_name*]
|
||||||
|
# This setting can be used to override the default
|
||||||
|
# postgresql server package name. If not specified, the module
|
||||||
|
# will use whatever package name is the default for your
|
||||||
|
# OS distro.
|
||||||
|
# [*devel_package_name*]
|
||||||
|
# This setting can be used to override the default
|
||||||
|
# postgresql devel package name. If not specified, the module
|
||||||
|
# will use whatever package name is the default for your
|
||||||
|
# OS distro.
|
||||||
|
# [*java_package_name*]
|
||||||
|
# This setting can be used to override the default
|
||||||
|
# postgresql java package name. If not specified, the module
|
||||||
|
# will use whatever package name is the default for your
|
||||||
|
# OS distro.
|
||||||
|
# [*service_name*]
|
||||||
|
# This setting can be used to override the default
|
||||||
|
# postgresql service name. If not specified, the module
|
||||||
|
# will use whatever service name is the default for your
|
||||||
|
# OS distro.
|
||||||
|
# [*user*]
|
||||||
|
# This setting can be used to override the default
|
||||||
|
# postgresql super user and owner of postgresql related files
|
||||||
|
# in the file system. If not specified, the module will use
|
||||||
|
# the user name 'postgres'.
|
||||||
|
# [*group*]
|
||||||
|
# This setting can be used to override the default
|
||||||
|
# postgresql user group to be used for related files
|
||||||
|
# in the file system. If not specified, the module will use
|
||||||
|
# the group name 'postgres'.
|
||||||
|
# [*run_initdb*]
|
||||||
|
# This setting can be used to explicitly call the initdb
|
||||||
|
# operation after server package is installed and before
|
||||||
|
# the postgresql service is started. If not specified, the
|
||||||
|
# module will decide whether to call initdb or not depending
|
||||||
|
# on your OS distro.
|
||||||
#
|
#
|
||||||
# === Examples:
|
# === Examples
|
||||||
#
|
#
|
||||||
# class { 'postgresql':
|
# class { 'postgresql':
|
||||||
# version => '9.2',
|
# version => '9.2',
|
||||||
|
@ -47,13 +103,36 @@ class postgresql (
|
||||||
$manage_package_repo = false,
|
$manage_package_repo = false,
|
||||||
$package_source = undef,
|
$package_source = undef,
|
||||||
$locale = undef,
|
$locale = undef,
|
||||||
$charset = 'UTF8'
|
$charset = 'UTF8',
|
||||||
|
$datadir = undef,
|
||||||
|
$confdir = undef,
|
||||||
|
$bindir = undef,
|
||||||
|
$client_package_name = undef,
|
||||||
|
$server_package_name = undef,
|
||||||
|
$devel_package_name = undef,
|
||||||
|
$java_package_name = undef,
|
||||||
|
$service_name = undef,
|
||||||
|
$user = undef,
|
||||||
|
$group = undef,
|
||||||
|
$run_initdb = undef
|
||||||
) {
|
) {
|
||||||
|
|
||||||
class { 'postgresql::params':
|
class { 'postgresql::params':
|
||||||
version => $version,
|
version => $version,
|
||||||
manage_package_repo => $manage_package_repo,
|
manage_package_repo => $manage_package_repo,
|
||||||
package_source => $package_source,
|
package_source => $package_source,
|
||||||
locale => $locale,
|
locale => $locale,
|
||||||
charset => $charset,
|
charset => $charset,
|
||||||
|
custom_datadir => $datadir,
|
||||||
|
custom_confdir => $confdir,
|
||||||
|
custom_bindir => $bindir,
|
||||||
|
custom_client_package_name => $client_package_name,
|
||||||
|
custom_server_package_name => $server_package_name,
|
||||||
|
custom_devel_package_name => $devel_package_name,
|
||||||
|
custom_java_package_name => $java_package_name,
|
||||||
|
custom_service_name => $service_name,
|
||||||
|
custom_user => $user,
|
||||||
|
custom_group => $group,
|
||||||
|
run_initdb => $run_initdb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
class postgresql::initdb(
|
class postgresql::initdb(
|
||||||
$datadir = $postgresql::params::datadir,
|
$datadir = $postgresql::params::datadir,
|
||||||
$encoding = $postgresql::params::charset,
|
$encoding = $postgresql::params::charset,
|
||||||
$group = 'postgres',
|
$group = $postgresql::params::group,
|
||||||
$initdb_path = $postgresql::params::initdb_path,
|
$initdb_path = $postgresql::params::initdb_path,
|
||||||
$user = 'postgres'
|
$user = $postgresql::params::user
|
||||||
) inherits postgresql::params {
|
) inherits postgresql::params {
|
||||||
# Build up the initdb command.
|
# Build up the initdb command.
|
||||||
#
|
#
|
||||||
|
|
|
@ -32,10 +32,21 @@ class postgresql::params(
|
||||||
$manage_package_repo = false,
|
$manage_package_repo = false,
|
||||||
$package_source = undef,
|
$package_source = undef,
|
||||||
$locale = undef,
|
$locale = undef,
|
||||||
$charset = 'UTF8'
|
$charset = 'UTF8',
|
||||||
|
$custom_datadir = undef,
|
||||||
|
$custom_confdir = undef,
|
||||||
|
$custom_bindir = undef,
|
||||||
|
$custom_client_package_name = undef,
|
||||||
|
$custom_server_package_name = undef,
|
||||||
|
$custom_devel_package_name = undef,
|
||||||
|
$custom_java_package_name = undef,
|
||||||
|
$custom_service_name = undef,
|
||||||
|
$custom_user = undef,
|
||||||
|
$custom_group = undef,
|
||||||
|
$run_initdb = undef,
|
||||||
) {
|
) {
|
||||||
$user = 'postgres'
|
$user = pick($custom_user, 'postgres')
|
||||||
$group = 'postgres'
|
$group = pick($custom_group, 'postgres')
|
||||||
$ip_mask_deny_postgres_user = '0.0.0.0/0'
|
$ip_mask_deny_postgres_user = '0.0.0.0/0'
|
||||||
$ip_mask_allow_all_users = '127.0.0.1/32'
|
$ip_mask_allow_all_users = '127.0.0.1/32'
|
||||||
$listen_addresses = 'localhost'
|
$listen_addresses = 'localhost'
|
||||||
|
@ -93,37 +104,37 @@ class postgresql::params(
|
||||||
# Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
|
# Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
|
||||||
case $::osfamily {
|
case $::osfamily {
|
||||||
'RedHat', 'Linux': {
|
'RedHat', 'Linux': {
|
||||||
$needs_initdb = true
|
$needs_initdb = pick($run_initdb, true)
|
||||||
$firewall_supported = true
|
$firewall_supported = true
|
||||||
$persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
|
$persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
|
||||||
|
|
||||||
if $version == $::postgres_default_version {
|
if $version == $::postgres_default_version {
|
||||||
$client_package_name = 'postgresql'
|
$client_package_name = pick($custom_client_package_name, 'postgresql')
|
||||||
$server_package_name = 'postgresql-server'
|
$server_package_name = pick($custom_server_package_name, 'postgresql-server')
|
||||||
$devel_package_name = 'postgresql-devel'
|
$devel_package_name = pick($custom_devel_package_name, 'postgresql-devel')
|
||||||
$java_package_name = 'postgresql-jdbc'
|
$java_package_name = pick($custom_java_package_name, 'postgresql-jdbc')
|
||||||
$service_name = 'postgresql'
|
$service_name = pick($custom_service_name, 'postgresql')
|
||||||
$bindir = '/usr/bin'
|
$bindir = pick($custom_bindir, '/usr/bin')
|
||||||
$datadir = '/var/lib/pgsql/data'
|
$datadir = pick($custom_datadir, '/var/lib/pgsql/data')
|
||||||
$confdir = $datadir
|
$confdir = pick($custom_confdir, $datadir)
|
||||||
} else {
|
} else {
|
||||||
$version_parts = split($version, '[.]')
|
$version_parts = split($version, '[.]')
|
||||||
$package_version = "${version_parts[0]}${version_parts[1]}"
|
$package_version = "${version_parts[0]}${version_parts[1]}"
|
||||||
$client_package_name = "postgresql${package_version}"
|
$client_package_name = pick($custom_client_package_name, "postgresql${package_version}")
|
||||||
$server_package_name = "postgresql${package_version}-server"
|
$server_package_name = pick($custom_server_package_name, "postgresql${package_version}-server")
|
||||||
$devel_package_name = "postgresql${package_version}-devel"
|
$devel_package_name = pick($custom_devel_package_name, "postgresql${package_version}-devel")
|
||||||
$java_package_name = "postgresql${package_version}-jdbc"
|
$java_package_name = pick($custom_java_package_name, "postgresql${package_version}-jdbc")
|
||||||
$service_name = "postgresql-${version}"
|
$service_name = pick($custom_service_name, "postgresql-${version}")
|
||||||
$bindir = "/usr/pgsql-${version}/bin"
|
$bindir = pick($custom_bindir, "/usr/pgsql-${version}/bin")
|
||||||
$datadir = "/var/lib/pgsql/${version}/data"
|
$datadir = pick($custom_datadir, "/var/lib/pgsql/${version}/data")
|
||||||
$confdir = $datadir
|
$confdir = pick($custom_confdir, $datadir)
|
||||||
}
|
}
|
||||||
|
|
||||||
$service_status = undef
|
$service_status = undef
|
||||||
}
|
}
|
||||||
|
|
||||||
'Debian': {
|
'Debian': {
|
||||||
$needs_initdb = false
|
$needs_initdb = pick($run_initdb, false)
|
||||||
$firewall_supported = false
|
$firewall_supported = false
|
||||||
# TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
|
# TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
|
||||||
#$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
|
#$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
|
||||||
|
@ -131,26 +142,25 @@ class postgresql::params(
|
||||||
|
|
||||||
case $::operatingsystem {
|
case $::operatingsystem {
|
||||||
'Debian': {
|
'Debian': {
|
||||||
$service_name = 'postgresql'
|
$service_name = pick($custom_service_name, 'postgresql')
|
||||||
}
|
}
|
||||||
|
|
||||||
'Ubuntu': {
|
'Ubuntu': {
|
||||||
# thanks, ubuntu
|
# thanks, ubuntu
|
||||||
if($::lsbmajdistrelease == '10' and !$manage_package_repo) {
|
if($::lsbmajdistrelease == '10' and !$manage_package_repo) {
|
||||||
$service_name = "postgresql-${version}"
|
$service_name = pick($custom_service_name, "postgresql-${version}")
|
||||||
} else {
|
} else {
|
||||||
$service_name = 'postgresql'
|
$service_name = pick($custom_service_name, 'postgresql')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$client_package_name = "postgresql-client-${version}"
|
$client_package_name = pick($custom_client_package_name, "postgresql-client-${version}")
|
||||||
$server_package_name = "postgresql-${version}"
|
$server_package_name = pick($custom_server_package_name, "postgresql-${version}")
|
||||||
$devel_package_name = 'libpq-dev'
|
$devel_package_name = pick($custom_devel_package_name, 'libpq-dev')
|
||||||
$java_package_name = 'libpostgresql-jdbc-java'
|
$java_package_name = pick($custom_java_package_name, 'libpostgresql-jdbc-java')
|
||||||
$bindir = "/usr/lib/postgresql/${version}/bin"
|
$bindir = pick($custom_bindir, "/usr/lib/postgresql/${version}/bin")
|
||||||
$datadir = "/var/lib/postgresql/${version}/main"
|
$datadir = pick($custom_datadir, "/var/lib/postgresql/${version}/main")
|
||||||
$confdir = "/etc/postgresql/${version}/main"
|
$confdir = pick($custom_confdir, "/etc/postgresql/${version}/main")
|
||||||
$service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+|online'"
|
$service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+|online'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,4 +174,5 @@ class postgresql::params(
|
||||||
$psql_path = "${bindir}/psql"
|
$psql_path = "${bindir}/psql"
|
||||||
$pg_hba_conf_path = "${confdir}/pg_hba.conf"
|
$pg_hba_conf_path = "${confdir}/pg_hba.conf"
|
||||||
$postgresql_conf_path = "${confdir}/postgresql.conf"
|
$postgresql_conf_path = "${confdir}/postgresql.conf"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ define postgresql::psql(
|
||||||
$unless,
|
$unless,
|
||||||
$command = $title,
|
$command = $title,
|
||||||
$refreshonly = false,
|
$refreshonly = false,
|
||||||
$user = 'postgres'
|
$user = $postgresql::params::user
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include postgresql::params
|
include postgresql::params
|
||||||
|
@ -35,6 +35,7 @@ define postgresql::psql(
|
||||||
}
|
}
|
||||||
|
|
||||||
$psql = "${postgresql::params::psql_path} ${no_password_option} --tuples-only --quiet --dbname ${db}"
|
$psql = "${postgresql::params::psql_path} ${no_password_option} --tuples-only --quiet --dbname ${db}"
|
||||||
|
|
||||||
$quoted_command = regsubst($command, '"', '\\"', 'G')
|
$quoted_command = regsubst($command, '"', '\\"', 'G')
|
||||||
$quoted_unless = regsubst($unless, '"', '\\"', 'G')
|
$quoted_unless = regsubst($unless, '"', '\\"', 'G')
|
||||||
|
|
||||||
|
|
|
@ -27,16 +27,21 @@ define postgresql::role(
|
||||||
) {
|
) {
|
||||||
include postgresql::params
|
include postgresql::params
|
||||||
|
|
||||||
|
Postgresql_psql {
|
||||||
|
psql_user => $postgresql::params::user,
|
||||||
|
psql_group => $postgresql::params::group,
|
||||||
|
psql_path => $postgresql::params::psql_path,
|
||||||
|
}
|
||||||
|
|
||||||
$login_sql = $login ? { true => 'LOGIN' , default => 'NOLOGIN' }
|
$login_sql = $login ? { true => 'LOGIN' , default => 'NOLOGIN' }
|
||||||
$createrole_sql = $createrole ? { true => 'CREATEROLE', default => 'NOCREATEROLE' }
|
$createrole_sql = $createrole ? { true => 'CREATEROLE', default => 'NOCREATEROLE' }
|
||||||
$createdb_sql = $createdb ? { true => 'CREATEDB' , default => 'NOCREATEDB' }
|
$createdb_sql = $createdb ? { true => 'CREATEDB' , default => 'NOCREATEDB' }
|
||||||
$superuser_sql = $superuser ? { true => 'SUPERUSER' , default => 'NOSUPERUSER' }
|
$superuser_sql = $superuser ? { true => 'SUPERUSER' , default => 'NOSUPERUSER' }
|
||||||
|
|
||||||
# TODO: FIXME: Will not correct the superuser / createdb / createrole / login status of a role that already exists
|
# TODO: FIXME: Will not correct the superuser / createdb / createrole / login status of a role that already exists
|
||||||
postgresql_psql {"CREATE ROLE ${username} ENCRYPTED PASSWORD '${password_hash}' ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql}":
|
postgresql_psql {"CREATE ROLE \"${username}\" ENCRYPTED PASSWORD '${password_hash}' ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql}":
|
||||||
db => $db,
|
db => $db,
|
||||||
psql_user => 'postgres',
|
psql_user => $postgresql::params::user,
|
||||||
unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}'",
|
unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}'",
|
||||||
cwd => $postgresql::params::datadir,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,26 +29,31 @@ define postgresql::tablespace(
|
||||||
{
|
{
|
||||||
include postgresql::params
|
include postgresql::params
|
||||||
|
|
||||||
|
Postgresql_psql {
|
||||||
|
psql_user => $postgresql::params::user,
|
||||||
|
psql_group => $postgresql::params::group,
|
||||||
|
psql_path => $postgresql::params::psql_path,
|
||||||
|
}
|
||||||
|
|
||||||
if ($owner == undef) {
|
if ($owner == undef) {
|
||||||
$owner_section = ''
|
$owner_section = ''
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$owner_section = "OWNER ${owner}"
|
$owner_section = "OWNER \"${owner}\""
|
||||||
}
|
}
|
||||||
|
|
||||||
$create_tablespace_command = "CREATE TABLESPACE ${spcname} ${owner_section} LOCATION '${location}'"
|
$create_tablespace_command = "CREATE TABLESPACE \"${spcname}\" ${owner_section} LOCATION '${location}'"
|
||||||
|
|
||||||
file { $location:
|
file { $location:
|
||||||
ensure => directory,
|
ensure => directory,
|
||||||
owner => 'postgres',
|
owner => $postgresql::params::user,
|
||||||
group => 'postgres',
|
group => $postgresql::params::group,
|
||||||
mode => '0700',
|
mode => '0700',
|
||||||
}
|
}
|
||||||
|
|
||||||
postgresql_psql { "Create tablespace '${spcname}'":
|
postgresql_psql { "Create tablespace '${spcname}'":
|
||||||
command => $create_tablespace_command,
|
command => $create_tablespace_command,
|
||||||
unless => "SELECT spcname FROM pg_tablespace WHERE spcname='${spcname}'",
|
unless => "SELECT spcname FROM pg_tablespace WHERE spcname='${spcname}'",
|
||||||
cwd => $postgresql::params::datadir,
|
|
||||||
require => [Class['postgresql::server'], File[$location]],
|
require => [Class['postgresql::server'], File[$location]],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,28 @@ describe 'postgresql', :type => :class do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
it { should include_class("postgresql") }
|
it { should include_class("postgresql") }
|
||||||
|
|
||||||
|
context 'support override params' do
|
||||||
|
let(:params) {{
|
||||||
|
:version => '8.4',
|
||||||
|
:manage_package_repo => true,
|
||||||
|
:package_source => '',
|
||||||
|
:locale => 'en_NG',
|
||||||
|
:charset => 'UTF8',
|
||||||
|
:datadir => '/srv/pgdata',
|
||||||
|
:confdir => '/opt/pg/etc',
|
||||||
|
:bindir => '/opt/pg/bin',
|
||||||
|
:client_package_name => 'my-postgresql-client',
|
||||||
|
:server_package_name => 'my-postgresql-server',
|
||||||
|
:devel_package_name => 'my-postgresql-devel',
|
||||||
|
:java_package_name => 'my-postgresql-java',
|
||||||
|
:service_name => 'my-postgresql',
|
||||||
|
:user => 'my-postgresql',
|
||||||
|
:group => 'my-postgresql',
|
||||||
|
:run_initdb => true,
|
||||||
|
}}
|
||||||
|
|
||||||
|
it { should include_class("postgresql") }
|
||||||
|
it { should include_class("postgresql::params") }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue