2012-06-08 23:00:24 +02:00
|
|
|
# Class: postgresql::config::afterservice
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
#
|
|
|
|
# [*postgres_password*] - postgres db user password.
|
|
|
|
#
|
|
|
|
# Actions:
|
|
|
|
#
|
|
|
|
# Requires:
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# This class is not intended to be used directly; it is
|
|
|
|
# managed by postgresl::config. It contains resources
|
|
|
|
# that should be handled *after* the postgres service
|
|
|
|
# has been started up.
|
|
|
|
#
|
|
|
|
# class { 'postgresql::config::afterservice':
|
|
|
|
# postgres_password => 'postgres'
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
class postgresql::config::afterservice(
|
|
|
|
$postgres_password = undef
|
|
|
|
) inherits postgresql::params {
|
|
|
|
if ($postgres_password != undef) {
|
|
|
|
# NOTE: this password-setting logic relies on the pg_hba.conf being configured
|
|
|
|
# to allow the postgres system user to connect via psql without specifying
|
2013-02-10 01:36:12 +01:00
|
|
|
# a password ('ident' or 'trust' security). This is the default
|
2012-06-08 23:00:24 +02:00
|
|
|
# for pg_hba.conf.
|
|
|
|
exec { 'set_postgres_postgrespw':
|
|
|
|
# This command works w/no password because we run it as postgres system user
|
2013-02-07 14:20:53 +01:00
|
|
|
command => "psql -c \"ALTER ROLE ${postgresql::params::user} PASSWORD '${postgres_password}'\"",
|
2012-06-08 23:00:24 +02:00
|
|
|
user => $postgresql::params::user,
|
|
|
|
group => $postgresql::params::group,
|
|
|
|
logoutput => true,
|
|
|
|
cwd => '/tmp',
|
|
|
|
# With this command we're passing -h to force TCP authentication, which does require
|
|
|
|
# a password. We specify the password via the PGPASSWORD environment variable. If
|
|
|
|
# the password is correct (current), this command will exit with an exit code of 0,
|
|
|
|
# which will prevent the main command from running.
|
2012-11-03 03:37:20 +01:00
|
|
|
unless => "env PGPASSWORD=\"${postgres_password}\" psql -h localhost -c 'select 1' > /dev/null",
|
2012-10-21 18:49:48 +02:00
|
|
|
path => '/usr/bin:/usr/local/bin:/bin',
|
2012-06-08 23:00:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|