initialize.pp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # == Class icingaweb2::initialize
  2. #
  3. # This class is used to initialize a default icingaweb2 db and user
  4. # Depends on the pupppetlabs-mysql module
  5. class icingaweb2::initialize {
  6. if $::icingaweb2::initialize {
  7. case $::operatingsystem {
  8. 'RedHat', 'CentOS': {
  9. case $::icingaweb2::web_db {
  10. 'mysql': {
  11. if $::icingaweb2::install_method == 'git' {
  12. $sql_schema_location = '/usr/share/icingaweb2/etc/schema/mysql.schema.sql'
  13. } else {
  14. $sql_schema_location = '/usr/share/doc/icingaweb2/schema/mysql.schema.sql'
  15. }
  16. exec { 'create db scheme':
  17. command => "mysql --defaults-file='/root/.my.cnf' ${::icingaweb2::web_db_name} < ${sql_schema_location}",
  18. unless => "mysql --defaults-file='/root/.my.cnf' ${::icingaweb2::web_db_name} -e \"SELECT 1 FROM icingaweb_user LIMIT 1;\"",
  19. notify => Exec['create web user']
  20. }
  21. exec { 'create web user':
  22. command => "mysql --defaults-file='/root/.my.cnf' ${::icingaweb2::web_db_name} -e \" INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('icingaadmin', 1, '\\\$1\\\$EzxLOFDr\\\$giVx3bGhVm4lDUAw6srGX1');\"",
  23. refreshonly => true,
  24. }
  25. }
  26. default: {
  27. fail "DB type ${::icingaweb2::web_db} not supported yet"
  28. }
  29. }
  30. }
  31. 'Debian', 'Ubuntu': {
  32. case $::icingaweb2::web_db {
  33. 'mysql': {
  34. $sql_schema_location = '/usr/share/icingaweb2/etc/schema/mysql.schema.sql'
  35. exec { 'create db scheme':
  36. command => "mysql -h ${::icingaweb2::web_db_host} -u${::icingaweb2::web_db_user} -p${::icingaweb2::web_db_pass} ${::icingaweb2::web_db_name} < ${sql_schema_location}",
  37. unless => "mysql -h ${::icingaweb2::web_db_host} -u${::icingaweb2::web_db_user} -p${::icingaweb2::web_db_pass} ${::icingaweb2::web_db_name} -e \"SELECT 1 FROM icingaweb_user LIMIT 1;\"",
  38. notify => Exec['create web user']
  39. }
  40. exec { 'create web user':
  41. command => "mysql -h ${::icingaweb2::web_db_host} -u${::icingaweb2::web_db_user} -p${::icingaweb2::web_db_pass} ${::icingaweb2::web_db_name} -e \" INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('icingaadmin', 1, '\\\$1\\\$EzxLOFDr\\\$giVx3bGhVm4lDUAw6srGX1');\"",
  42. refreshonly => true,
  43. }
  44. }
  45. default: {
  46. fail "DB type ${::icingaweb2::web_db} not supported yet"
  47. }
  48. }
  49. }
  50. default: {
  51. fail "Managing repositories for ${::operatingsystem} is not supported."
  52. }
  53. }
  54. }
  55. }