install.pp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 or RedHat systems:
  30. 'CentOS', 'RedHat': {
  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. include apt
  51. #On Debian (7) icinga2 packages are on backports
  52. if $use_debmon_repo == false {
  53. include apt::backports
  54. } else {
  55. apt::source { 'debmon':
  56. location => 'http://debmon.org/debmon',
  57. release => "debmon-${lsbdistcodename}",
  58. repos => 'main',
  59. key_source => 'http://debmon.org/debmon/repo.key',
  60. key => '29D662D2',
  61. include_src => false,
  62. # backports repo use 200
  63. pin => '300'
  64. }
  65. }
  66. }
  67. #Fail if we're on any other OS:
  68. default: { fail("${::operatingsystem} is not supported!") }
  69. }
  70. }
  71. }
  72. #Install packages for Icinga 2:
  73. class icinga2::server::install::packages inherits icinga2::server {
  74. include icinga2::server
  75. #Install the Icinga 2 package
  76. package {$icinga2_server_package:
  77. ensure => installed,
  78. provider => $package_provider,
  79. }
  80. if $server_install_nagios_plugins == true {
  81. #Install the Nagios plugins packages:
  82. package {$icinga2_server_plugin_packages:
  83. ensure => installed,
  84. provider => $package_provider,
  85. install_options => $server_plugin_package_install_options,
  86. }
  87. }
  88. if $install_mail_utils_package == true {
  89. #Install the package that has the 'mail' binary in it so we can send notifications:
  90. package {$icinga2_server_mail_package:
  91. ensure => installed,
  92. provider => $package_provider,
  93. install_options => $server_plugin_package_install_options,
  94. }
  95. }
  96. #Pick the right DB lib package name based on the database type the user selected:
  97. case $server_db_type {
  98. #MySQL:
  99. 'mysql': { $icinga2_server_db_connector_package = 'icinga2-ido-mysql'}
  100. #Postgres:
  101. 'pgsql': { $icinga2_server_db_connector_package = 'icinga2-ido-pgsql'}
  102. default: { fail("${icinga2::params::server_db_type} is not a supported database! Please specify either 'mysql' for MySQL or 'pgsql' for Postgres.") }
  103. }
  104. #Install the IDO database connector package. See:
  105. #http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc#!/icinga2/latest/doc/module/icinga2/chapter/getting-started#configuring-db-ido
  106. package {$icinga2_server_db_connector_package:
  107. ensure => installed,
  108. provider => $package_provider,
  109. }
  110. }
  111. #This class contains exec resources
  112. class icinga2::server::install::execs inherits icinga2::server {
  113. include icinga2::server
  114. #Configure database schemas and IDO modules
  115. case $server_db_type {
  116. 'mysql': {
  117. #Load the MySQL DB schema:
  118. exec { 'mysql_schema_load':
  119. user => 'root',
  120. path => '/usr/bin:/usr/sbin:/bin/:/sbin',
  121. command => "mysql -u ${db_user} -p${db_password} ${db_name} < ${server_db_schema_path} && touch /etc/icinga2/mysql_schema_loaded.txt",
  122. creates => '/etc/icinga2/mysql_schema_loaded.txt',
  123. require => Class['icinga2::server::install::packages'],
  124. }
  125. #Enable the MySQL IDO module:
  126. exec { 'mysql_module_enable':
  127. user => 'root',
  128. path => '/usr/bin:/usr/sbin:/bin/:/sbin',
  129. command => '/usr/sbin/icinga2 enable feature ido-mysql && touch /etc/icinga2/mysql_module_loaded.txt',
  130. creates => '/etc/icinga2/mysql_module_loaded.txt',
  131. require => Exec['mysql_schema_load'],
  132. }
  133. }
  134. 'pgsql': {
  135. #Load the Postgres DB schema:
  136. exec { 'postgres_schema_load':
  137. user => 'root',
  138. path => '/usr/bin:/usr/sbin:/bin/:/sbin',
  139. 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",
  140. creates => '/etc/icinga2/postgres_schema_loaded.txt',
  141. require => Class['icinga2::server::install::packages'],
  142. }
  143. #Enable the Postgres IDO module:
  144. exec { 'postgres_module_enable':
  145. user => 'root',
  146. path => '/usr/bin:/usr/sbin:/bin/:/sbin',
  147. command => '/usr/sbin/icinga2 enable feature ido-pgsql && touch /etc/icinga2/postgres_module_loaded.txt',
  148. creates => '/etc/icinga2/postgres_module_loaded.txt',
  149. require => Exec['postgres_schema_load'],
  150. }
  151. }
  152. default: { fail("${server_db_type} is not supported!") }
  153. }
  154. }