database.pp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # == Class: oradb::database
  2. #
  3. #
  4. # action = createDatabase|deleteDatabase
  5. # databaseType = MULTIPURPOSE|DATA_WAREHOUSING|OLTP
  6. #
  7. #
  8. # oradb::database{ 'testDb':
  9. # oracleBase => '/oracle',
  10. # oracleHome => '/oracle/product/11.2/db',
  11. # version => "11.2",
  12. # user => 'oracle',
  13. # group => 'dba',
  14. # downloadDir => '/install',
  15. # action => 'create',
  16. # dbName => 'test',
  17. # dbDomain => 'oracle.com',
  18. # sysPassword => 'Welcome01',
  19. # systemPassword => 'Welcome01',
  20. # dataFileDestination => "/oracle/oradata",
  21. # recoveryAreaDestination => "/oracle/flash_recovery_area",
  22. # characterSet => "AL32UTF8",
  23. # nationalCharacterSet => "UTF8",
  24. # initParams => "open_cursors=1000,processes=600,job_queue_processes=4,compatible=11.2.0.0.0",
  25. # sampleSchema => 'TRUE',
  26. # memoryPercentage => "40",
  27. # memoryTotal => "800",
  28. # databaseType => "MULTIPURPOSE",
  29. # emConfiguration => "NONE",
  30. # require => Oradb::Listener['start listener'],
  31. # }
  32. #
  33. #
  34. #
  35. define oradb::database( $oracleBase = undef,
  36. $oracleHome = undef,
  37. $version = "11.2",
  38. $user = 'oracle',
  39. $group = 'dba',
  40. $downloadDir = '/install',
  41. $action = 'create',
  42. $dbName = 'orcl',
  43. $dbDomain = undef,
  44. $sysPassword = 'Welcome01',
  45. $systemPassword = 'Welcome01',
  46. $dataFileDestination = undef,
  47. $recoveryAreaDestination = undef,
  48. $characterSet = "AL32UTF8",
  49. $nationalCharacterSet = "UTF8",
  50. $initParams = undef,
  51. $sampleSchema = TRUE,
  52. $memoryPercentage = "40",
  53. $memoryTotal = "800",
  54. $databaseType = "MULTIPURPOSE",
  55. $emConfiguration = "NONE", # CENTRAL|LOCAL|ALL|NONE
  56. $storageType = "FS", #FS|CFS|ASM
  57. $asmSnmpPassword = 'Welcome01',
  58. $asmDiskgroup = 'DATA',
  59. $recoveryDiskgroup = undef,
  60. )
  61. {
  62. if $version == "11.2" or $version == "12.1" {
  63. } else {
  64. fail("Unrecognized version")
  65. }
  66. $continue = true
  67. if ( $continue ) {
  68. case $::kernel {
  69. Linux,SunOS: {
  70. $execPath = "${oracleHome}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:"
  71. $path = $downloadDir
  72. Exec {
  73. path => $execPath,
  74. user => $user,
  75. group => $group,
  76. environment => ["USER=${user}",],
  77. logoutput => true,
  78. }
  79. File {
  80. ensure => present,
  81. mode => 0775,
  82. owner => $user,
  83. group => $group,
  84. }
  85. }
  86. default: {
  87. fail("Unrecognized operating system")
  88. }
  89. }
  90. $sanitized_title = regsubst($title, "[^a-zA-Z0-9.-]", "_", "G")
  91. $filename = "${path}/database_${sanitized_title}.rsp"
  92. if $action == 'create' {
  93. $operationType = 'createDatabase'
  94. } elsif $action == 'delete' {
  95. $operationType = 'deleteDatabase'
  96. } else {
  97. fail("Unrecognized database action")
  98. }
  99. if $dbDomain {
  100. $globalDbName = "${dbName}.${dbDomain}"
  101. } else {
  102. $globalDbName = $dbName
  103. }
  104. if ! defined(File[$filename]) {
  105. file { $filename:
  106. ensure => present,
  107. content => template("oradb/dbca_${version}.rsp.erb"),
  108. }
  109. }
  110. if $action == 'create' {
  111. exec { "install oracle database ${title}":
  112. command => "dbca -silent -responseFile ${filename}",
  113. require => File[$filename],
  114. creates => "${oracleBase}/admin/${dbName}",
  115. timeout => 0,
  116. }
  117. } elsif $action == 'delete' {
  118. exec { "delete oracle database ${title}":
  119. command => "dbca -silent -responseFile ${filename}",
  120. require => File[$filename],
  121. onlyif => "ls ${oracleBase}/admin/${dbName}",
  122. timeout => 0,
  123. }
  124. }
  125. }
  126. }