params.pp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # Class: postgresql::params
  2. #
  3. # The postgresql configuration settings.
  4. #
  5. # Parameters:
  6. #
  7. # Actions:
  8. #
  9. # Requires:
  10. #
  11. # Sample Usage:
  12. #
  13. # TODO: add real docs
  14. # This class allows you to use a newer version of postgres, rather than your
  15. # system's default version.
  16. #
  17. # If you want to do that, note that it is important that you use the '->',
  18. # or a before/require metaparameter to make sure that the `params`
  19. # class is evaluated before any of the other classes in the module.
  20. #
  21. # Also note that this class includes the ability to automatically manage
  22. # the yumrepo resource. If you'd prefer to manage the repo yourself, simply pass
  23. # 'false' or omit the 'manage_repo' parameter--it defaults to 'false'. You will
  24. # still need to use the 'params' class to specify the postgres version
  25. # number, though, in order for the other classes to be able to find the
  26. # correct paths to the postgres dirs.
  27. class postgresql::params(
  28. $version = $::postgres_default_version,
  29. $manage_package_repo = false,
  30. $package_source = undef,
  31. $locale = undef,
  32. $charset = 'UTF8',
  33. $custom_datadir = undef,
  34. $custom_confdir = undef,
  35. $custom_bindir = undef,
  36. $custom_client_package_name = undef,
  37. $custom_server_package_name = undef,
  38. $custom_contrib_package_name = undef,
  39. $custom_devel_package_name = undef,
  40. $custom_java_package_name = undef,
  41. $custom_service_name = undef,
  42. $custom_user = undef,
  43. $custom_group = undef,
  44. $run_initdb = undef
  45. ) {
  46. $user = pick($custom_user, 'postgres')
  47. $group = pick($custom_group, 'postgres')
  48. $ip_mask_deny_postgres_user = '0.0.0.0/0'
  49. $ip_mask_allow_all_users = '127.0.0.1/32'
  50. $listen_addresses = 'localhost'
  51. $ipv4acls = []
  52. $ipv6acls = []
  53. # TODO: figure out a way to make this not platform-specific
  54. $manage_redhat_firewall = false
  55. if ($manage_package_repo) {
  56. case $::osfamily {
  57. 'RedHat': {
  58. $rh_pkg_source = pick($package_source, 'yum.postgresql.org')
  59. case $rh_pkg_source {
  60. 'yum.postgresql.org': {
  61. class { 'postgresql::package_source::yum_postgresql_org':
  62. version => $version
  63. }
  64. }
  65. default: {
  66. fail("Unsupported package source '${rh_pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'")
  67. }
  68. }
  69. }
  70. 'Debian': {
  71. class { 'postgresql::package_source::apt_postgresql_org': }
  72. }
  73. default: {
  74. fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
  75. }
  76. }
  77. }
  78. # This is a bit hacky, but if the puppet nodes don't have pluginsync enabled,
  79. # they will fail with a not-so-helpful error message. Here we are explicitly
  80. # verifying that the custom fact exists (which implies that pluginsync is
  81. # enabled and succeeded). If not, we fail with a hint that tells the user
  82. # that pluginsync might not be enabled. Ideally this would be handled directly
  83. # in puppet.
  84. if ($::postgres_default_version == undef) {
  85. fail "No value for postgres_default_version facter fact; it's possible that you don't have pluginsync enabled."
  86. }
  87. case $::operatingsystem {
  88. default: {
  89. $service_provider = undef
  90. }
  91. }
  92. # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
  93. case $::osfamily {
  94. 'RedHat', 'Linux': {
  95. $needs_initdb = pick($run_initdb, true)
  96. $firewall_supported = true
  97. $persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
  98. if $version == $::postgres_default_version {
  99. $client_package_name = pick($custom_client_package_name, 'postgresql')
  100. $server_package_name = pick($custom_server_package_name, 'postgresql-server')
  101. $contrib_package_name = pick($custom_contrib_package_name,'postgresql-contrib')
  102. $devel_package_name = pick($custom_devel_package_name, 'postgresql-devel')
  103. $java_package_name = pick($custom_java_package_name, 'postgresql-jdbc')
  104. $service_name = pick($custom_service_name, 'postgresql')
  105. $bindir = pick($custom_bindir, '/usr/bin')
  106. $datadir = pick($custom_datadir, '/var/lib/pgsql/data')
  107. $confdir = pick($custom_confdir, $datadir)
  108. } else {
  109. $version_parts = split($version, '[.]')
  110. $package_version = "${version_parts[0]}${version_parts[1]}"
  111. $client_package_name = pick($custom_client_package_name, "postgresql${package_version}")
  112. $server_package_name = pick($custom_server_package_name, "postgresql${package_version}-server")
  113. $contrib_package_name = pick($custom_contrib_package_name,"postgresql${package_version}-contrib")
  114. $devel_package_name = pick($custom_devel_package_name, "postgresql${package_version}-devel")
  115. $java_package_name = pick($custom_java_package_name, "postgresql${package_version}-jdbc")
  116. $service_name = pick($custom_service_name, "postgresql-${version}")
  117. $bindir = pick($custom_bindir, "/usr/pgsql-${version}/bin")
  118. $datadir = pick($custom_datadir, "/var/lib/pgsql/${version}/data")
  119. $confdir = pick($custom_confdir, $datadir)
  120. }
  121. $service_status = undef
  122. $python_package_name="python-psycopg2"
  123. }
  124. 'Debian': {
  125. $firewall_supported = false
  126. # TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
  127. #$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
  128. if $manage_package_repo == true {
  129. $needs_initdb = pick($run_initdb, true)
  130. $service_name = pick($custom_service_name, 'postgresql')
  131. } else {
  132. $needs_initdb = pick($run_initdb, false)
  133. case $::operatingsystem {
  134. 'Debian': {
  135. $service_name = pick($custom_service_name, 'postgresql')
  136. }
  137. 'Ubuntu': {
  138. # thanks, ubuntu
  139. if($::lsbmajdistrelease == '10') {
  140. $service_name = pick($custom_service_name, "postgresql-${version}")
  141. } else {
  142. $service_name = pick($custom_service_name, 'postgresql')
  143. }
  144. }
  145. }
  146. }
  147. $client_package_name = pick($custom_client_package_name, "postgresql-client-${version}")
  148. $server_package_name = pick($custom_server_package_name, "postgresql-${version}")
  149. $contrib_package_name = pick($custom_contrib_package_name, "postgresql-contrib-${version}")
  150. $devel_package_name = pick($custom_devel_package_name, 'libpq-dev')
  151. $java_package_name = pick($custom_java_package_name, 'libpostgresql-jdbc-java')
  152. $bindir = pick($custom_bindir, "/usr/lib/postgresql/${version}/bin")
  153. $datadir = pick($custom_datadir, "/var/lib/postgresql/${version}/main")
  154. $confdir = pick($custom_confdir, "/etc/postgresql/${version}/main")
  155. $service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+|online'"
  156. $python_package_name = "python-psycopg2"
  157. }
  158. default: {
  159. fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
  160. }
  161. }
  162. $initdb_path = "${bindir}/initdb"
  163. $createdb_path = "${bindir}/createdb"
  164. $psql_path = "${bindir}/psql"
  165. $pg_hba_conf_path = "${confdir}/pg_hba.conf"
  166. $postgresql_conf_path = "${confdir}/postgresql.conf"
  167. }