init.pp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing,
  14. # software distributed under the License is distributed on an
  15. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. # KIND, either express or implied. See the License for the
  17. # specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. #
  21. class hdp(
  22. $service_state = undef,
  23. $pre_installed_pkgs = undef
  24. )
  25. {
  26. import 'params.pp'
  27. include hdp::params
  28. Exec { logoutput => 'on_failure' }
  29. group { $hdp::params::hadoop_user_group :
  30. ensure => present
  31. }
  32. #TODO: think not needed and also there seems to be a puppet bug around this and ldap
  33. hdp::user { $hdp::params::hadoop_user:
  34. gid => $hdp::params::hadoop_user_group
  35. }
  36. Group[$hdp::params::hadoop_user_group] -> Hdp::User[$hdp::params::hadoop_user]
  37. class { 'hdp::snmp': service_state => 'running'}
  38. class { 'hdp::create_smoke_user': }
  39. if ($pre_installed_pkgs != undef) {
  40. class { 'hdp::pre_install_pkgs': }
  41. }
  42. #turns off selinux
  43. class { 'hdp::set_selinux': }
  44. if ($service_state != 'uninstalled') {
  45. if ($hdp::params::lzo_enabled == true) {
  46. @hdp::lzo::package{ 32:}
  47. @hdp::lzo::package{ 64:}
  48. }
  49. }
  50. #TODO: treat consistently
  51. if ($service_state != 'uninstalled') {
  52. if ($hdp::params::snappy_enabled == true) {
  53. include hdp::snappy::package
  54. }
  55. }
  56. Hdp::Package<|title == 'hadoop 32'|> -> Hdp::Package<|title == 'hbase'|>
  57. Hdp::Package<|title == 'hadoop 64'|> -> Hdp::Package<|title == 'hbase'|>
  58. #TODO: just for testing
  59. class{ 'hdp::iptables':
  60. ensure => stopped,
  61. }
  62. case $hdp::params::hdp_os_type {
  63. centos6, rhel6: {
  64. hdp::package{ 'glibc-rhel6':
  65. ensure => 'present',
  66. size => $size,
  67. java_needed => false,
  68. lzo_needed => false
  69. }
  70. }
  71. }
  72. }
  73. class hdp::pre_install_pkgs
  74. {
  75. if ($service_state == 'installed_and_configured') {
  76. hdp::exec{ 'yum install $pre_installed_pkgs':
  77. command => "yum install -y $pre_installed_pkgs"
  78. }
  79. } elsif ($service_state == 'uninstalled') {
  80. hdp::exec{ 'yum erase $pre_installed_pkgs':
  81. command => "yum erase -y $pre_installed_pkgs"
  82. }
  83. }
  84. }
  85. class hdp::create_smoke_user()
  86. {
  87. $smoke_group = $hdp::params::smoke_user_group
  88. $smoke_user = $hdp::params::smokeuser
  89. $security_enabled = $hdp::params::security_enabled
  90. group { $smoke_group :
  91. ensure => present
  92. }
  93. hdp::user { $smoke_user:}
  94. $cmd = "usermod -g $smoke_group $smoke_user"
  95. $check_group_cmd = "id -gn $smoke_user | grep $smoke_group"
  96. hdp::exec{ $cmd:
  97. command => $cmd,
  98. unless => $check_group_cmd
  99. }
  100. if ($security_enabled == true) {
  101. $secure_uid = $hdp::params::smoketest_user_secure_uid
  102. $cmd_set_uid = "usermod -u ${secure_uid} ${smoke_user}"
  103. $cmd_set_uid_check = "id -u ${smoke_user} | grep ${secure_uid}"
  104. hdp::exec{ $cmd_set_uid:
  105. command => $cmd_set_uid,
  106. unless => $cmd_set_uid_check,
  107. require => Hdp::User[$smoke_user]
  108. }
  109. }
  110. Group[$smoke_group] -> Hdp::User[$smoke_user] -> Hdp::Exec[$cmd]
  111. }
  112. class hdp::set_selinux()
  113. {
  114. $cmd = "/bin/echo 0 > /selinux/enforce"
  115. hdp::exec{ $cmd:
  116. command => $cmd,
  117. unless => "head -n 1 /selinux/enforce | grep ^0$"
  118. }
  119. }
  120. define hdp::user(
  121. $gid = $hdp::params::hadoop_user_group,
  122. $just_validate = undef
  123. )
  124. {
  125. $user_info = $hdp::params::user_info[$name]
  126. if ($just_validate != undef) {
  127. $just_val = $just_validate
  128. } elsif (($user_info == undef) or ("|${user_info}|" == '||')){ #tests for different versions of Puppet
  129. $just_val = false
  130. } else {
  131. $just_val = $user_info[just_validate]
  132. }
  133. if ($just_val == true) {
  134. exec { "user ${name} exists":
  135. command => "su - ${name} -c 'ls /dev/null' >/dev/null 2>&1",
  136. path => ['/bin']
  137. }
  138. } else {
  139. user { $name:
  140. ensure => present,
  141. managehome => true,
  142. #gid => $gid, #TODO either remove this to support LDAP env or fix it
  143. shell => '/bin/bash'
  144. }
  145. }
  146. }
  147. define hdp::directory(
  148. $owner = $hdp::params::hadoop_user,
  149. $group = $hdp::params::hadoop_user_group,
  150. $mode = undef,
  151. $ensure = directory,
  152. $force = undef,
  153. $service_state = 'running'
  154. )
  155. {
  156. if (($service_state == 'uninstalled') and ($wipeoff_data == true)) {
  157. file { $name :
  158. ensure => absent,
  159. owner => $owner,
  160. group => $group,
  161. mode => $mode,
  162. force => $force
  163. }
  164. } elsif ($service_state != 'uninstalled') {
  165. file { $name :
  166. ensure => present,
  167. owner => $owner,
  168. group => $group,
  169. mode => $mode,
  170. force => $force
  171. }
  172. }
  173. }
  174. #TODO: check on -R flag and use of recurse
  175. define hdp::directory_recursive_create(
  176. $owner = $hdp::params::hadoop_user,
  177. $group = $hdp::params::hadoop_user_group,
  178. $mode = undef,
  179. $context_tag = undef,
  180. $ensure = directory,
  181. $force = undef,
  182. $service_state = 'running'
  183. )
  184. {
  185. hdp::exec {"mkdir -p ${name}" :
  186. command => "mkdir -p ${name}",
  187. creates => $name
  188. }
  189. #to take care of setting ownership and mode
  190. hdp::directory { $name :
  191. owner => $owner,
  192. group => $group,
  193. mode => $mode,
  194. ensure => $ensure,
  195. force => $force,
  196. service_state => $service_state
  197. }
  198. Hdp::Exec["mkdir -p ${name}"] -> Hdp::Directory[$name]
  199. }
  200. ### helper to do exec
  201. define hdp::exec(
  202. $command,
  203. $refreshonly = undef,
  204. $unless = undef,
  205. $onlyif = undef,
  206. $path = $hdp::params::exec_path,
  207. $user = undef,
  208. $creates = undef,
  209. $tries = 1,
  210. $timeout = 300,
  211. $try_sleep = undef,
  212. $initial_wait = undef,
  213. $logoutput = 'on_failure',
  214. $cwd = undef
  215. )
  216. {
  217. if (($initial_wait != undef) and ($initial_wait != "undef")) {
  218. #passing in creates and unless so dont have to wait if condition has been acheived already
  219. hdp::wait { "service ${name}" :
  220. wait_time => $initial_wait,
  221. creates => $creates,
  222. unless => $unless,
  223. onlyif => $onlyif,
  224. path => $path
  225. }
  226. }
  227. exec { $name :
  228. command => $command,
  229. refreshonly => $refreshonly,
  230. path => $path,
  231. user => $user,
  232. creates => $creates,
  233. unless => $unless,
  234. onlyif => $onlyif,
  235. tries => $tries,
  236. timeout => $timeout,
  237. try_sleep => $try_sleep,
  238. logoutput => $logoutput,
  239. cwd => $cwd
  240. }
  241. anchor{ "hdp::exec::${name}::begin":} -> Exec[$name] -> anchor{ "hdp::exec::${name}::end":}
  242. if (($initial_wait != undef) and ($initial_wait != "undef")) {
  243. Anchor["hdp::exec::${name}::begin"] -> Hdp::Wait["service ${name}"] -> Exec[$name]
  244. }
  245. }
  246. #### utilities for waits
  247. define hdp::wait(
  248. $wait_time,
  249. $creates = undef,
  250. $unless = undef,
  251. $onlyif = undef,
  252. $path = undef #used for unless
  253. )
  254. {
  255. exec { "wait ${name} ${wait_time}" :
  256. command => "/bin/sleep ${wait_time}",
  257. creates => $creates,
  258. unless => $unless,
  259. onlyif => $onlyif,
  260. path => $path
  261. }
  262. }
  263. ##### temp
  264. class hdp::iptables($ensure)
  265. {
  266. #TODO: just temp so not considering things like saving firewall rules
  267. service { 'iptables':
  268. ensure => $ensure
  269. }
  270. }