install.pp 5.4 KB

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