diff --git a/Modulefile b/Modulefile index 8bb7005..e471bc3 100644 --- a/Modulefile +++ b/Modulefile @@ -7,5 +7,5 @@ summary 'PostgreSQL defined resource types' license 'Apache' project_page 'https://github.com/puppetlabs/puppet-postgresql/issues' -dependency 'puppetlabs/stdlib', '>= 2.0.0' +dependency 'puppetlabs/stdlib', '>= 3.2.0' dependency 'puppetlabs/firewall', '>= 0.0.4' diff --git a/manifests/devel.pp b/manifests/devel.pp index 9bf8b67..b4f59ae 100644 --- a/manifests/devel.pp +++ b/manifests/devel.pp @@ -17,8 +17,9 @@ class postgresql::devel( $package_ensure = 'present' ) inherits postgresql::params { - package { 'postgresql_devel': + package { 'postgresql-devel': ensure => $package_ensure, name => $package_name, + tag => 'postgresql', } } diff --git a/manifests/init.pp b/manifests/init.pp index 9f24c28..a296f39 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -21,9 +21,10 @@ class postgresql ( $package_ensure = 'present' ) inherits postgresql::params { - package { 'postgresql_client': + package { 'postgresql-client': ensure => $package_ensure, name => $package_name, + tag => 'postgresql', } } diff --git a/manifests/package_source/yum_postgresql_org.pp b/manifests/package_source/yum_postgresql_org.pp index b45409c..bdd33ca 100644 --- a/manifests/package_source/yum_postgresql_org.pp +++ b/manifests/package_source/yum_postgresql_org.pp @@ -17,7 +17,6 @@ class postgresql::package_source::yum_postgresql_org( gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}", } - if defined(Package['postgresql-server']) { - Yumrepo['yum.postgresql.org'] -> Package['postgresql-server'] - } -} \ No newline at end of file + Yumrepo["yum.postgresql.org"] -> Package<|tag == 'postgresql'|> + +} diff --git a/manifests/package_source_info.pp b/manifests/package_source_info.pp deleted file mode 100644 index e688359..0000000 --- a/manifests/package_source_info.pp +++ /dev/null @@ -1,51 +0,0 @@ -# TODO: add real docs - -# This class allows you to use a newer version of postgres, rather than your -# system's default version. -# -# Note that it is important that you use the '->', or a -# before/require metaparameter to make sure that the `package_source_info` -# class is evaluated before any of the other classes in the module. -# -# Also note that this class includes the ability to automatically manage -# the yumrepo resource. If you'd prefer to manage the repo yourself, simply pass -# 'false' or omit the 'manage_repo' parameter--it defaults to 'false'. You will -# still need to use the 'package_source_info' class to specify the postgres version -# number, though, in order for the other classes to be able to find the -# correct paths to the postgres dirs. - -class postgresql::package_source_info( - $version, - $manage_repo = false, - $source = '' -) { - - if ($manage_repo) { - case $::osfamily { - 'RedHat': { - if ! $source { - $pkg_source = 'yum.postgresql.org' - } else { - $pkg_source = $source - } - - case $pkg_source { - 'yum.postgresql.org': { - class { "postgresql::package_source::yum_postgresql_org": - version => $version - } - } - - default: { - fail("Unsupported package source '${pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'") - } - } - - } - - default: { - fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian") - } - } - } -} \ No newline at end of file diff --git a/manifests/params.pp b/manifests/params.pp index 33a7045..a0afce8 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,7 +10,28 @@ # # Sample Usage: # -class postgresql::params { + +# TODO: add real docs + +# This class allows you to use a newer version of postgres, rather than your +# system's default version. +# +# If you want to do that, note that it is important that you use the '->', +# or a before/require metaparameter to make sure that the `params` +# class is evaluated before any of the other classes in the module. +# +# Also note that this class includes the ability to automatically manage +# the yumrepo resource. If you'd prefer to manage the repo yourself, simply pass +# 'false' or omit the 'manage_repo' parameter--it defaults to 'false'. You will +# still need to use the 'params' class to specify the postgres version +# number, though, in order for the other classes to be able to find the +# correct paths to the postgres dirs. + +class postgresql::params( + $version = $::postgres_default_version, + $manage_package_repo = false, + $package_source = undef, +) { $user = 'postgres' $group = 'postgres' $ip_mask_deny_postgres_user = '0.0.0.0/0' @@ -21,6 +42,32 @@ class postgresql::params { # TODO: figure out a way to make this not platform-specific $manage_redhat_firewall = false + + if ($manage_package_repo) { + case $::osfamily { + 'RedHat': { + $rh_pkg_source = pick($package_source, 'yum.postgresql.org') + + case $rh_pkg_source { + 'yum.postgresql.org': { + class { "postgresql::package_source::yum_postgresql_org": + version => $version + } + } + + default: { + fail("Unsupported package source '${rh_pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'") + } + } + } + + default: { + fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian") + } + } + } + + # This is a bit hacky, but if the puppet nodes don't have pluginsync enabled, # they will fail with a not-so-helpful error message. Here we are explicitly # verifying that the custom fact exists (which implies that pluginsync is @@ -31,14 +78,6 @@ class postgresql::params { fail "No value for postgres_default_version facter fact; it's possible that you don't have pluginsync enabled." } - - if defined(Class[Postgresql::Package_source_info]) { - $version = $postgresql::package_source_info::version - } else { - $version = $::postgres_default_version - } - - case $::operatingsystem { default: { $service_provider = undef diff --git a/manifests/server.pp b/manifests/server.pp index e45111e..2eee1c0 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -26,12 +26,9 @@ class postgresql::server ( package { 'postgresql-server': ensure => $package_ensure, name => $package_name, + tag => 'postgresql', } - if defined(Yumrepo['yum.postgresql.org']) { - Yumrepo['yum.postgresql.org'] -> Package['postgresql-server'] - } - $config_class = {} $config_class['postgresql::config'] = $config_hash diff --git a/manifests/validate_db_connection.pp b/manifests/validate_db_connection.pp index 92da12b..1a0c59e 100644 --- a/manifests/validate_db_connection.pp +++ b/manifests/validate_db_connection.pp @@ -58,6 +58,7 @@ define postgresql::validate_db_connection( package { 'postgresql-client': ensure => present, name => $client_package_name, + tag => 'postgresql', } # TODO: port to ruby diff --git a/spec/support/postgres_test_config.rb b/spec/support/postgres_test_config.rb index 88bbcfa..b2c5332 100644 --- a/spec/support/postgres_test_config.rb +++ b/spec/support/postgres_test_config.rb @@ -4,11 +4,11 @@ module PostgresTestConfig # valuable for final testing. This constant allows you to toggle between # strict testing and less strict testing--the latter being useful for # development purposes. - HardCoreTesting = false + HardCoreTesting = true # If this value is set to true, then each VM will be suspended after the tests # against it are completed. This will slow things down a ton during # iterative development, but will save a lot of system resources by not # keeping all of the VMs running at the same time. - SuspendVMsAfterSuite = false + SuspendVMsAfterSuite = true end diff --git a/spec/test_module/manifests/non_default/test_db.pp b/spec/test_module/manifests/non_default/test_db.pp index b7fae67..bd6805b 100644 --- a/spec/test_module/manifests/non_default/test_db.pp +++ b/spec/test_module/manifests/non_default/test_db.pp @@ -18,10 +18,10 @@ class postgresql_tests::non_default::test_db($db) { - class { "postgresql::package_source_info": - version => '9.2', - source => 'yum.postgresql.org', - manage_repo => true, + class { "postgresql::params": + version => '9.2', + manage_package_repo => true, + package_source => 'yum.postgresql.org', } -> class { "postgresql::server": } -> diff --git a/spec/test_module/manifests/non_default/test_install.pp b/spec/test_module/manifests/non_default/test_install.pp index fa44931..c3ca885 100644 --- a/spec/test_module/manifests/non_default/test_install.pp +++ b/spec/test_module/manifests/non_default/test_install.pp @@ -1,10 +1,10 @@ class postgresql_tests::non_default::test_install { - class { "postgresql::package_source_info": - version => '9.2', - source => 'yum.postgresql.org', - manage_repo => true, + class { "postgresql::params": + version => '9.2', + manage_package_repo => true, + package_source => 'yum.postgresql.org', } -> class { "postgresql::server": } -} \ No newline at end of file +} diff --git a/tests/server-yum-postgresql-org.pp b/tests/server-yum-postgresql-org.pp index 8f1e85f..3698196 100644 --- a/tests/server-yum-postgresql-org.pp +++ b/tests/server-yum-postgresql-org.pp @@ -3,20 +3,21 @@ # default version. # # Note that it is important that you use the '->', or a -# before/require metaparameter to make sure that the `package_source_info` +# before/require metaparameter to make sure that the `params` # class is evaluated before any of the other classes in the module. # # Also note that this example includes automatic management of the yumrepo # resource. If you'd prefer to manage the repo yourself, simply pass 'false' # or omit the 'manage_repo' parameter--it defaults to 'false'. You will still -# need to use the 'package_source_info' class to specify the postgres version +# need to use the 'params' class to specify the postgres version # number, though, in order for the other classes to be able to find the # correct paths to the postgres dirs. -class { "postgresql::package_source_info": - version => '9.2', - source => 'yum.postgresql.org', - manage_repo => true, + +class { "postgresql::params": + version => '9.2', + manage_package_repo => true, + package_source => 'yum.postgresql.org', } -> -class { "postgresql::server": } \ No newline at end of file +class { "postgresql::server": }