install.pp 4.9 KB

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