params.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. ) {
  34. $user = 'postgres'
  35. $group = 'postgres'
  36. $ip_mask_deny_postgres_user = '0.0.0.0/0'
  37. $ip_mask_allow_all_users = '127.0.0.1/32'
  38. $listen_addresses = 'localhost'
  39. $ipv4acls = []
  40. $ipv6acls = []
  41. # TODO: figure out a way to make this not platform-specific
  42. $manage_redhat_firewall = false
  43. if ($manage_package_repo) {
  44. case $::osfamily {
  45. 'RedHat': {
  46. $rh_pkg_source = pick($package_source, 'yum.postgresql.org')
  47. case $rh_pkg_source {
  48. 'yum.postgresql.org': {
  49. class { 'postgresql::package_source::yum_postgresql_org':
  50. version => $version
  51. }
  52. }
  53. default: {
  54. fail("Unsupported package source '${rh_pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'")
  55. }
  56. }
  57. }
  58. 'Debian': {
  59. class { 'postgresql::package_source::apt_postgresql_org': }
  60. }
  61. default: {
  62. fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
  63. }
  64. }
  65. }
  66. # This is a bit hacky, but if the puppet nodes don't have pluginsync enabled,
  67. # they will fail with a not-so-helpful error message. Here we are explicitly
  68. # verifying that the custom fact exists (which implies that pluginsync is
  69. # enabled and succeeded). If not, we fail with a hint that tells the user
  70. # that pluginsync might not be enabled. Ideally this would be handled directly
  71. # in puppet.
  72. if ($::postgres_default_version == undef) {
  73. fail 'No value for postgres_default_version facter fact; it\'s possible that you don\'t have pluginsync enabled.'
  74. }
  75. case $::operatingsystem {
  76. default: {
  77. $service_provider = undef
  78. }
  79. }
  80. # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
  81. case $::osfamily {
  82. 'RedHat', 'Linux': {
  83. $needs_initdb = true
  84. $firewall_supported = true
  85. $persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
  86. if $version == $::postgres_default_version {
  87. $client_package_name = 'postgresql'
  88. $server_package_name = 'postgresql-server'
  89. $devel_package_name = 'postgresql-devel'
  90. $service_name = 'postgresql'
  91. $bindir = '/usr/bin'
  92. $datadir = '/var/lib/pgsql/data'
  93. $confdir = $datadir
  94. } else {
  95. $version_parts = split($version, '[.]')
  96. $package_version = "${version_parts[0]}${version_parts[1]}"
  97. $client_package_name = "postgresql${package_version}"
  98. $server_package_name = "postgresql${package_version}-server"
  99. $devel_package_name = "postgresql${package_version}-devel"
  100. $service_name = "postgresql-${version}"
  101. $bindir = "/usr/pgsql-${version}/bin"
  102. $datadir = "/var/lib/pgsql/${version}/data"
  103. $confdir = $datadir
  104. }
  105. $service_status = undef
  106. }
  107. 'Debian': {
  108. $needs_initdb = false
  109. $firewall_supported = false
  110. # TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
  111. #$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
  112. case $::operatingsystem {
  113. 'Debian': {
  114. $service_name = 'postgresql'
  115. }
  116. 'Ubuntu': {
  117. # thanks, ubuntu
  118. if($::lsbmajdistrelease == '10' and !$manage_package_repo) {
  119. $service_name = "postgresql-${version}"
  120. } else {
  121. $service_name = 'postgresql'
  122. }
  123. }
  124. }
  125. $client_package_name = "postgresql-client-${version}"
  126. $server_package_name = "postgresql-${version}"
  127. $devel_package_name = 'libpq-dev'
  128. $bindir = "/usr/lib/postgresql/${version}/bin"
  129. $datadir = "/var/lib/postgresql/${version}/main"
  130. $confdir = "/etc/postgresql/${version}/main"
  131. $service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+|online'"
  132. }
  133. default: {
  134. fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
  135. }
  136. }
  137. $initdb_path = "${bindir}/initdb"
  138. $createdb_path = "${bindir}/createdb"
  139. $psql_path = "${bindir}/psql"
  140. $pg_hba_conf_path = "${confdir}/pg_hba.conf"
  141. $postgresql_conf_path = "${confdir}/postgresql.conf"
  142. }