puppetlabs/puppet-postgresql — pull request #106 by fhrbek (2013-02-01 12:49:44+00:00)
Title: Generalization to provide more flexibility in postgresql configuration

This PR contains a generalization of postgres configuration.

Some of the changes have already been suggested in a different PR (https://github.com/puppetlabs/puppet-postgresql/pull/95) but I rewrote them in a slightly different way (using "pick" instead of "if-else" etc.). In addition to those cosmetic changes I think that there was a bug in suggested changes regarding the initdb implementation and ensuring that the data directory exists and is owned by postgres - it did not work for me if the path consisted of more than two segments. I added a function called "descend_path" so that even deeper directories could be ensured and only the leaf directory is set to be owned by the postgres user and group.

I also added more configuration parameters so that the module would be usable for installing pe-postgres. An example how to install pe-postgres:

```puppet
class pe_postgresql(
$version = '9.1'
) {

class { 'postgresql::params':
custom_client_package_name => 'pe-postgresql',
custom_server_package_name => 'pe-postgresql-server',
custom_devel_package_name => 'pe-postgresql-devel',
custom_datadir => "/opt/puppet/var/lib/pgsql/${version}/data",
custom_bindir => '/opt/puppet/bin',
custom_service_name => 'pe-postgresql',
custom_user => 'pe-postgres',
custom_group => 'pe-postgres',
locale => 'en_US.UTF8',
force_initdb => true,
} ->
class { 'postgresql::server':
service_status => 'service pe-postgresql status',
}
}
```
I have verified that this works provided the packages (pe-postgresql and pe-postgresql-server) are installed manually prior to running puppet (we have no repository with those packages). It would be an option to create a local repository from them but there might be problems with certain platforms that don't support local repositories (Solaris?).

Finally I have some questions:

1) Service status didn't work as defined in the module. To make it work I had to override the definition (as you can see in the example) to "service pe-postgresql status"). I think that this would be worth fixing in the module but it would require investigating the behavior on various platforms (although I believe that "service status" should be the standard instead of the complicated command that's there at the moment)

2) When is initdb required?
There's some logic that determines if initdb will be called or not. Basically it looks like it is called for redhat OS family machines but not for debian. What's meant by that? In any case, we do need to call initdb for pe-postgres even on ubuntu. For now I added yet another option "force_initdb" which does the trick but again, maybe it should be solved in a different way.