config.pp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # Manage puppet configuration. See README.md for more details.
  2. class puppetdb::master::config (
  3. $puppetdb_server = $::fqdn,
  4. $puppetdb_port = defined(Class['puppetdb']) ? {
  5. true => $::puppetdb::disable_ssl ? {
  6. true => 8080,
  7. default => 8081,
  8. },
  9. default => 8081,
  10. },
  11. $puppetdb_disable_ssl = defined(Class['puppetdb']) ? {
  12. true => $::puppetdb::disable_ssl,
  13. default => false,
  14. },
  15. $masterless = $puppetdb::params::masterless,
  16. $puppetdb_soft_write_failure = false,
  17. $manage_routes = true,
  18. $manage_storeconfigs = true,
  19. $manage_report_processor = false,
  20. $manage_config = true,
  21. $strict_validation = true,
  22. $enable_reports = false,
  23. $puppet_confdir = $puppetdb::params::puppet_confdir,
  24. $puppet_conf = $puppetdb::params::puppet_conf,
  25. $terminus_package = $puppetdb::params::terminus_package,
  26. $puppet_service_name = $puppetdb::params::puppet_service_name,
  27. $puppetdb_startup_timeout = $puppetdb::params::puppetdb_startup_timeout,
  28. $test_url = $puppetdb::params::test_url,
  29. $restart_puppet = true,
  30. ) inherits puppetdb::params {
  31. # **WARNING**: Ugly hack to work around a yum bug with metadata parsing. This
  32. # should not be copied, replicated or even looked at. In short, never rename
  33. # your packages...
  34. #
  35. # With `yum` we can't have the termini package override the terminus package
  36. # because that would prevent users from installing v2.3 of the terminus in
  37. # PC1. We tried using a dummy terminus-3 metadata package which pulled in
  38. # termini-3.latest as a dependency and put a requires terminus >= 3, <4. The
  39. # idea was that doing `yum install puppetdb-termini-3.x.y-1.el7` would pull up
  40. # the terminus package to the dummy 3 version, but `yum` has a bug which
  41. # requires that both the dummy package and termini be installed in the same
  42. # transaction, i.e. `yum install puppetdb-termini-3.x.y-1.el7
  43. # puppetdb-terminus-3` which is impossible to do via Puppet.
  44. #
  45. # This will orphan some old terminus files (from pre-puppet-agent, i.e. puppet
  46. # 3.x) that are orphaned as part of the Puppet 3 to Puppet 4 upgrade anyways
  47. # and some of the new terminus files temporarily. If this exec fails all you
  48. # need to do is reinstall whatever 2.3 version of the terminus was already
  49. # installed to revert the change.
  50. if !($puppetdb::params::puppetdb_version in ['present','absent'])
  51. and versioncmp($puppetdb::params::puppetdb_version, '3.0.0') >= 0
  52. and $::osfamily in ['RedHat','Suse'] {
  53. exec { 'Remove puppetdb-terminus metadata for upgrade':
  54. command => 'rpm -e --justdb puppetdb-terminus',
  55. path => '/sbin/:/bin/',
  56. onlyif => 'rpm -q puppetdb-terminus',
  57. before => Package[$terminus_package],
  58. }
  59. }
  60. package { $terminus_package:
  61. ensure => $puppetdb::params::puppetdb_version,
  62. }
  63. if ($strict_validation) {
  64. # Validate the puppetdb connection. If we can't connect to puppetdb then we
  65. # *must* not perform the other configuration steps, or else
  66. $conn_puppetdb_server = $manage_config ? {
  67. true => $puppetdb_server,
  68. default => undef,
  69. }
  70. $conn_puppetdb_port = $manage_config ? {
  71. true => $puppetdb_port,
  72. default => undef,
  73. }
  74. $conn_puppetdb_ssl = $puppetdb_disable_ssl ? {
  75. true => false,
  76. default => true,
  77. }
  78. puppetdb_conn_validator { 'puppetdb_conn':
  79. puppetdb_server => $conn_puppetdb_server,
  80. puppetdb_port => $conn_puppetdb_port,
  81. use_ssl => $conn_puppetdb_ssl,
  82. timeout => $puppetdb_startup_timeout,
  83. require => Package[$terminus_package],
  84. test_url => $test_url,
  85. }
  86. # This is a bit of puppet chicanery that allows us to create a
  87. # conditional dependency. Basically, we're saying that "if the PuppetDB
  88. # service is being managed in this same catalog, it needs to come before
  89. # this validator."
  90. Service<|title == $puppetdb::params::puppetdb_service|> -> Puppetdb_conn_validator['puppetdb_conn']
  91. }
  92. # Conditionally manage the `routes.yaml` file. Restart the puppet service
  93. # if changes are made.
  94. if ($manage_routes) {
  95. $routes_require = $strict_validation ? {
  96. true => Puppetdb_conn_validator['puppetdb_conn'],
  97. default => Package[$terminus_package],
  98. }
  99. class { 'puppetdb::master::routes':
  100. puppet_confdir => $puppet_confdir,
  101. masterless => $masterless,
  102. require => $routes_require,
  103. }
  104. }
  105. # Conditionally manage the storeconfigs settings in `puppet.conf`. We don't
  106. # need to trigger a restart of the puppet master service for this one, because
  107. # it polls it automatically.
  108. if ($manage_storeconfigs) {
  109. $storeconfigs_require = $strict_validation ? {
  110. true => Puppetdb_conn_validator['puppetdb_conn'],
  111. default => Package[$terminus_package],
  112. }
  113. class { 'puppetdb::master::storeconfigs':
  114. puppet_conf => $puppet_conf,
  115. masterless => $masterless,
  116. require => $storeconfigs_require,
  117. }
  118. }
  119. # Conditionally manage the puppetdb report processor setting in `puppet.conf`.
  120. # We don't need to trigger a restart of the puppet master service for this one,
  121. # because it polls it automatically.
  122. if ($manage_report_processor) {
  123. $report_processor_require = $strict_validation ? {
  124. true => Puppetdb_conn_validator['puppetdb_conn'],
  125. default => Package[$terminus_package],
  126. }
  127. class { 'puppetdb::master::report_processor':
  128. puppet_conf => $puppet_conf,
  129. masterless => $masterless,
  130. enable => $enable_reports,
  131. require => $report_processor_require,
  132. }
  133. }
  134. if ($manage_config) {
  135. # Manage the `puppetdb.conf` file. Restart the puppet service if changes
  136. # are made.
  137. $puppetdb_conf_require = $strict_validation ? {
  138. true => Puppetdb_conn_validator['puppetdb_conn'],
  139. default => Package[$terminus_package],
  140. }
  141. class { 'puppetdb::master::puppetdb_conf':
  142. server => $puppetdb_server,
  143. port => $puppetdb_port,
  144. soft_write_failure => $puppetdb_soft_write_failure,
  145. puppet_confdir => $puppet_confdir,
  146. legacy_terminus => $puppetdb::params::terminus_package == 'puppetdb-terminus',
  147. require => $puppetdb_conf_require,
  148. }
  149. }
  150. if ($restart_puppet) {
  151. # We will need to restart the puppet master service if certain config
  152. # files are changed, so here we make sure it's in the catalog.
  153. if ! defined(Service[$puppet_service_name]) {
  154. service { $puppet_service_name:
  155. ensure => running,
  156. }
  157. }
  158. if ($manage_config) {
  159. Class['puppetdb::master::puppetdb_conf'] ~> Service[$puppet_service_name]
  160. }
  161. if ($manage_routes) {
  162. Class['puppetdb::master::routes'] ~> Service[$puppet_service_name]
  163. }
  164. if ($manage_report_processor) {
  165. Class['puppetdb::master::report_processor'] ~> Service[$puppet_service_name]
  166. }
  167. }
  168. }