defaultusersfolders.pp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # == Define: wls::utils::defaultusersfolders
  2. #
  3. # create users/ group , download folder and oracle home
  4. #
  5. #
  6. ##
  7. define wls::utils::defaultusersfolders(
  8. $oracleHome = undef,
  9. $oraInventory = undef,
  10. $createUser = true,
  11. $user = 'oracle',
  12. $group = 'dba',
  13. $downloadDir = '/install',
  14. ) {
  15. case $operatingsystem {
  16. CentOS, RedHat, OracleLinux, Ubuntu, Debian, SLES, Solaris: {
  17. $execPath = "/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:"
  18. Exec { path => $execPath,
  19. user => $user,
  20. group => $group,
  21. logoutput => true,
  22. }
  23. File {
  24. ensure => present,
  25. mode => 0775,
  26. owner => $user,
  27. group => $group,
  28. backup => false,
  29. }
  30. }
  31. windows: {
  32. $execPath = "C:\\unxutils\\bin;C:\\unxutils\\usr\\local\\wbin;C:\\Windows\\system32;C:\\Windows"
  33. $checkCommand = "C:\\Windows\\System32\\cmd.exe /c"
  34. Exec { path => $execPath,
  35. }
  36. File { ensure => present,
  37. mode => 0777,
  38. backup => false,
  39. }
  40. }
  41. }
  42. if ( $createUser ) {
  43. # for linux , create a oracle user plus a dba group
  44. case $operatingsystem {
  45. CentOS, RedHat, OracleLinux, Ubuntu, Debian, SLES: {
  46. if ! defined(Group[$group]) {
  47. group { $group :
  48. ensure => present,
  49. }
  50. }
  51. if ! defined(User[$user]) {
  52. # http://raftaman.net/?p=1311 for generating password
  53. user { $user :
  54. ensure => present,
  55. groups => $group,
  56. shell => '/bin/bash',
  57. password => '$1$DSJ51vh6$4XzzwyIOk6Bi/54kglGk3.',
  58. home => "/home/${user}",
  59. comment => 'created by Puppet',
  60. require => Group[$group],
  61. managehome => true,
  62. }
  63. }
  64. }
  65. Solaris: {
  66. if ! defined(Group[$group]) {
  67. group { $group :
  68. ensure => present,
  69. }
  70. }
  71. if ! defined(User[$user]) {
  72. # http://raftaman.net/?p=1311 for generating password
  73. user { $user :
  74. ensure => present,
  75. groups => $group,
  76. shell => '/bin/bash',
  77. password => '$1$DSJ51vh6$4XzzwyIOk6Bi/54kglGk3.',
  78. home => "/export/home/${user}",
  79. comment => 'created by Puppet',
  80. require => Group[$group],
  81. managehome => true,
  82. }
  83. }
  84. }
  85. }
  86. }
  87. # create all folders
  88. case $operatingsystem {
  89. CentOS, RedHat, OracleLinux, Ubuntu, Debian, SLES, Solaris: {
  90. if ! defined(Exec ["create ${oracleHome} directory"]) {
  91. exec { "create ${oracleHome} directory":
  92. command => "mkdir -p ${oracleHome}",
  93. unless => "test -d ${oracleHome}",
  94. user => 'root',
  95. }
  96. }
  97. if ! defined(Exec ["create ${downloadDir} home directory"]) {
  98. exec { "create ${downloadDir} home directory":
  99. command => "mkdir -p ${downloadDir}",
  100. unless => "test -d ${downloadDir}",
  101. user => 'root',
  102. }
  103. }
  104. }
  105. windows: {
  106. # make dir folder suitable for unxtools
  107. $oracleHomeWin = slash_replace( $oracleHome )
  108. $downloadDirWin = slash_replace( $downloadDir )
  109. if ! defined(Exec ["create ${oracleHome} directory"]) {
  110. exec { "create ${oracleHome} directory":
  111. command => "${checkCommand} mkdir ${oracleHomeWin}",
  112. unless => "${checkCommand} dir ${oracleHomeWin}",
  113. }
  114. }
  115. if ! defined(Exec ["create ${downloadDir} home directory"]) {
  116. exec { "create ${downloadDir} home directory":
  117. command => "${checkCommand} mkdir ${downloadDirWin}",
  118. unless => "${checkCommand} dir ${downloadDirWin}",
  119. }
  120. }
  121. }
  122. default: {
  123. fail("Unrecognized operating system")
  124. }
  125. }
  126. if ( $createUser == true and $operatingsystem != "windows" ) {
  127. # also set permissions on downloadDir
  128. if ! defined(File[$downloadDir]) {
  129. # check oracle install folder
  130. file { $downloadDir :
  131. ensure => directory,
  132. recurse => false,
  133. replace => false,
  134. require => [User[$user],Exec["create ${downloadDir} home directory"]],
  135. }
  136. }
  137. # also set permissions on oracleHome
  138. if ! defined(File[$oracleHome]) {
  139. file { $oracleHome:
  140. ensure => directory,
  141. recurse => false,
  142. replace => false,
  143. require => [User[$user],Exec["create ${oracleHome} directory"]],
  144. }
  145. }
  146. if ( $oraInventory != undef ) {
  147. # also set permissions on oraInventory
  148. if ! defined(File[$oraInventory]) {
  149. file { $oraInventory:
  150. ensure => directory,
  151. recurse => false,
  152. replace => false,
  153. require => [User[$user],Exec["create ${oracleHome} directory"]],
  154. }
  155. }
  156. }
  157. } else {
  158. # also set permissions on downloadDir
  159. if ! defined(File[$downloadDir]) {
  160. # check oracle install folder
  161. file { $downloadDir :
  162. ensure => directory,
  163. recurse => false,
  164. replace => false,
  165. require => Exec["create ${downloadDir} home directory"],
  166. }
  167. }
  168. # also set permissions on oracleHome
  169. if ! defined(File[$oracleHome]) {
  170. file { $oracleHome:
  171. ensure => directory,
  172. recurse => false,
  173. replace => false,
  174. require => Exec["create ${oracleHome} directory"],
  175. }
  176. }
  177. if ( $oraInventory != undef ) {
  178. case $operatingsystem {
  179. CentOS, RedHat, OracleLinux, Ubuntu, Debian, SLES, Solaris: {
  180. # also set permissions on oraInventory
  181. if ! defined(File[$oraInventory]) {
  182. file { $oraInventory:
  183. ensure => directory,
  184. recurse => false,
  185. replace => false,
  186. require => Exec["create ${oracleHome} directory"],
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }