install.pp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # == Class: icinga2::server::install
  2. #
  3. # This class installs the server components for the Icinga 2 monitoring system.
  4. #
  5. # === Parameters
  6. #
  7. # Coming soon...
  8. #
  9. # === Examples
  10. #
  11. # Coming soon...
  12. #
  13. class icinga2::server::install inherits icinga2::server {
  14. include icinga2::server
  15. #Apply our classes in the right order. Use the squiggly arrows (~>) to ensure that the
  16. #class left is applied before the class on the right and that it also refreshes the
  17. #class on the right.
  18. #
  19. #Here, we're setting up the package repos first, then installing the packages:
  20. class{'icinga2::server::install::repos':} ~>
  21. class{'icinga2::server::install::packages':} ~>
  22. class{'icinga2::server::install::execs':} ->
  23. Class['icinga2::server::install']
  24. }
  25. class icinga2::server::install::repos inherits icinga2::server {
  26. include icinga2::server
  27. if $manage_repos == true {
  28. case $::operatingsystem {
  29. #CentOS systems:
  30. 'CentOS': {
  31. #Add the official Icinga Yum repository: http://packages.icinga.org/epel/
  32. yumrepo { 'icinga2_yum_repo':
  33. baseurl => "http://packages.icinga.org/epel/${::operatingsystemmajrelease}/release/",
  34. descr => 'Icinga 2 Yum repository',
  35. enabled => 1,
  36. gpgcheck => 1,
  37. gpgkey => 'http://packages.icinga.org/icinga.key'
  38. }
  39. }
  40. #Ubuntu systems:
  41. 'Ubuntu': {
  42. #Include the apt module's base class so we can...
  43. include apt
  44. #...use the apt module to add the Icinga 2 PPA from launchpad.net:
  45. # https://launchpad.net/~formorer/+archive/ubuntu/icinga
  46. apt::ppa { 'ppa:formorer/icinga': }
  47. }
  48. #Debian systems:
  49. 'Debian': {
  50. #On Debian (7) icinga2 packages are on backports
  51. if $use_debmon_repo == false {
  52. include apt::backports
  53. } else {
  54. apt::source { 'debmon':
  55. location => 'http://debmon.org/debmon',
  56. release => "debmon-${lsbdistcodename}",
  57. repos => 'main',
  58. key_source => 'http://debmon.org/debmon/repo.key',
  59. key => 'BC7D020A',
  60. include_src => false,
  61. # backports repo use 200
  62. pin => '300'
  63. }
  64. }
  65. }
  66. #Fail if we're on any other OS:
  67. default: { fail("${::operatingsystem} is not supported!") }
  68. }
  69. }
  70. }
  71. #Install packages for Icinga 2:
  72. class icinga2::server::install::packages inherits icinga2::server {
  73. include icinga2::server
  74. #Install the Icinga 2 package
  75. package {$icinga2_server_package:
  76. ensure => installed,
  77. provider => $package_provider,
  78. }
  79. if $server_install_nagios_plugins == true {
  80. #Install the Nagios plugins packages:
  81. package {$icinga2_server_plugin_packages:
  82. ensure => installed,
  83. provider => $package_provider,
  84. install_options => $server_plugin_package_install_options,
  85. }
  86. }
  87. if $install_mail_utils_package == true {
  88. #Install the package that has the 'mail' binary in it so we can send notifications:
  89. package {$icinga2_server_mail_package:
  90. ensure => installed,
  91. provider => $package_provider,
  92. install_options => $server_plugin_package_install_options,
  93. }
  94. }
  95. #Pick the right DB lib package name based on the database type the user selected:
  96. case $server_db_type {
  97. #MySQL:
  98. 'mysql': { $icinga2_server_db_connector_package = 'icinga2-ido-mysql'}
  99. #Postgres:
  100. 'pgsql': { $icinga2_server_db_connector_package = 'icinga2-ido-pgsql'}
  101. default: { fail("${icinga2::params::server_db_type} is not a supported database! Please specify either 'mysql' for MySQL or 'pgsql' for Postgres.") }
  102. }
  103. #Install the IDO database connector package. See:
  104. #http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc#!/icinga2/latest/doc/module/icinga2/chapter/getting-started#configuring-db-ido
  105. package {$icinga2_server_db_connector_package:
  106. ensure => installed,
  107. provider => $package_provider,
  108. }
  109. }
  110. #This class contains exec resources
  111. class icinga2::server::install::execs inherits icinga2::server {
  112. include icinga2::server
  113. #Configure database schemas and IDO modules
  114. case $server_db_type {
  115. 'mysql': {
  116. #Load the MySQL DB schema:
  117. exec { 'mysql_schema_load':
  118. user => 'root',
  119. path => '/usr/bin:/usr/sbin:/bin/:/sbin',
  120. command => "mysql -u ${db_user} -p${db_password} ${db_name} < ${server_db_schema_path} && touch /etc/icinga2/mysql_schema_loaded.txt",
  121. creates => '/etc/icinga2/mysql_schema_loaded.txt',
  122. require => Class['icinga2::server::install::packages'],
  123. }
  124. #Enable the MySQL IDO module:
  125. exec { 'mysql_module_enable':
  126. user => 'root',
  127. path => '/usr/bin:/usr/sbin:/bin/:/sbin',
  128. command => '/usr/sbin/icinga2-enable-feature ido-mysql && touch /etc/icinga2/mysql_module_loaded.txt',
  129. creates => '/etc/icinga2/mysql_module_loaded.txt',
  130. require => Exec['mysql_schema_load'],
  131. }
  132. }
  133. 'pgsql': {
  134. #Load the Postgres DB schema:
  135. exec { 'postgres_schema_load':
  136. user => 'root',
  137. path => '/usr/bin:/usr/sbin:/bin/:/sbin',
  138. command => "su - postgres -c 'export PGPASSWORD='${db_password}' && psql -U ${db_user} -h localhost -d ${db_name} < ${server_db_schema_path}' && export PGPASSWORD='' && touch /etc/icinga2/postgres_schema_loaded.txt",
  139. creates => '/etc/icinga2/postgres_schema_loaded.txt',
  140. require => Class['icinga2::server::install::packages'],
  141. }
  142. #Enable the Postgres IDO module:
  143. exec { 'postgres_module_enable':
  144. user => 'root',
  145. path => '/usr/bin:/usr/sbin:/bin/:/sbin',
  146. command => '/usr/sbin/icinga2-enable-feature ido-pgsql && touch /etc/icinga2/postgres_module_loaded.txt',
  147. creates => '/etc/icinga2/postgres_module_loaded.txt',
  148. require => Exec['postgres_schema_load'],
  149. }
  150. }
  151. default: { fail("${server_db_type} is not supported!") }
  152. }
  153. }