bebox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (402) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +78 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +163 -0
  5. data/LICENSE +21 -0
  6. data/README.md +372 -0
  7. data/Rakefile +8 -0
  8. data/bebox.gemspec +40 -0
  9. data/bin/bebox +5 -0
  10. data/lib/bebox/cli.rb +42 -0
  11. data/lib/bebox/commands/commands_helper.rb +33 -0
  12. data/lib/bebox/commands/environment_commands.rb +46 -0
  13. data/lib/bebox/commands/general_commands.rb +24 -0
  14. data/lib/bebox/commands/node_commands.rb +68 -0
  15. data/lib/bebox/commands/prepare_commands.rb +59 -0
  16. data/lib/bebox/commands/project_commands.rb +44 -0
  17. data/lib/bebox/commands/provision_commands.rb +145 -0
  18. data/lib/bebox/environment.rb +114 -0
  19. data/lib/bebox/logger.rb +51 -0
  20. data/lib/bebox/node.rb +308 -0
  21. data/lib/bebox/profile.rb +102 -0
  22. data/lib/bebox/project.rb +259 -0
  23. data/lib/bebox/provision.rb +257 -0
  24. data/lib/bebox/role.rb +103 -0
  25. data/lib/bebox/version.rb +3 -0
  26. data/lib/bebox/wizards/environment_wizard.rb +45 -0
  27. data/lib/bebox/wizards/node_wizard.rb +163 -0
  28. data/lib/bebox/wizards/profile_wizard.rb +91 -0
  29. data/lib/bebox/wizards/project_wizard.rb +175 -0
  30. data/lib/bebox/wizards/provision_wizard.rb +80 -0
  31. data/lib/bebox/wizards/role_wizard.rb +97 -0
  32. data/lib/bebox.rb +2 -0
  33. data/lib/deb/puppet_3.6.0/augeas-lenses_0.10.0-0ubuntu4_all.deb +0 -0
  34. data/lib/deb/puppet_3.6.0/debconf-utils_1.5.42ubuntu1_all.deb +0 -0
  35. data/lib/deb/puppet_3.6.0/facter_2.0.1-1puppetlabs1_amd64.deb +0 -0
  36. data/lib/deb/puppet_3.6.0/hiera_1.3.2-1puppetlabs1_all.deb +0 -0
  37. data/lib/deb/puppet_3.6.0/libaugeas-ruby1.8_0.3.0-1.1ubuntu4_amd64.deb +0 -0
  38. data/lib/deb/puppet_3.6.0/libaugeas-ruby_0.3.0-1.1ubuntu4_all.deb +0 -0
  39. data/lib/deb/puppet_3.6.0/libaugeas0_0.10.0-0ubuntu4_amd64.deb +0 -0
  40. data/lib/deb/puppet_3.6.0/libjson-ruby_1.6.3-1_all.deb +0 -0
  41. data/lib/deb/puppet_3.6.0/libruby1.8_1.8.7.352-2ubuntu1.4_amd64.deb +0 -0
  42. data/lib/deb/puppet_3.6.0/libruby_4.8_all.deb +0 -0
  43. data/lib/deb/puppet_3.6.0/libshadow-ruby1.8_1.4.1-8build1_amd64.deb +0 -0
  44. data/lib/deb/puppet_3.6.0/puppet-common_3.6.0-1puppetlabs1_all.deb +0 -0
  45. data/lib/deb/puppet_3.6.0/puppet_3.6.0-1puppetlabs1_all.deb +0 -0
  46. data/lib/deb/puppet_3.6.0/ruby-json_1.6.3-1_amd64.deb +0 -0
  47. data/lib/deb/puppet_3.6.0/ruby-rgen_0.6.5-1puppetlabs1_all.deb +0 -0
  48. data/lib/deb/puppet_3.6.0/ruby1.8_1.8.7.352-2ubuntu1.4_amd64.deb +0 -0
  49. data/lib/deb/puppet_3.6.0/ruby_4.8_all.deb +0 -0
  50. data/lib/deb/puppet_3.6.0/virt-what_1.11-1_amd64.deb +0 -0
  51. data/lib/templates/node/Vagrantfile.erb +18 -0
  52. data/lib/templates/node/deploy_vagrant_node.erb +3 -0
  53. data/lib/templates/node/node.yml.erb +3 -0
  54. data/lib/templates/node/prepared_node.yml.erb +4 -0
  55. data/lib/templates/node/provisioned_node.yml.erb +4 -0
  56. data/lib/templates/project/Capfile.erb +2 -0
  57. data/lib/templates/project/Gemfile.erb +5 -0
  58. data/lib/templates/project/config/deploy/environment.erb +40 -0
  59. data/lib/templates/project/config/deploy/vagrant.erb +42 -0
  60. data/lib/templates/project/config/deploy.erb +120 -0
  61. data/lib/templates/project/dot_bebox.erb +4 -0
  62. data/lib/templates/project/gitignore.erb +7 -0
  63. data/lib/templates/project/ubuntu_dependencies +10 -0
  64. data/lib/templates/puppet/default_profiles/base/fundamental/ruby/Puppetfile +0 -0
  65. data/lib/templates/puppet/default_profiles/base/fundamental/ruby/manifests/init.pp +24 -0
  66. data/lib/templates/puppet/default_profiles/base/fundamental/sudo/Puppetfile +0 -0
  67. data/lib/templates/puppet/default_profiles/base/fundamental/sudo/manifests/init.pp +22 -0
  68. data/lib/templates/puppet/default_profiles/base/fundamental/users/Puppetfile +0 -0
  69. data/lib/templates/puppet/default_profiles/base/fundamental/users/manifests/init.pp +18 -0
  70. data/lib/templates/puppet/default_profiles/base/security/fail2ban/Puppetfile +2 -0
  71. data/lib/templates/puppet/default_profiles/base/security/fail2ban/manifests/init.pp +28 -0
  72. data/lib/templates/puppet/default_profiles/base/security/iptables/Puppetfile +2 -0
  73. data/lib/templates/puppet/default_profiles/base/security/iptables/manifests/init.pp +27 -0
  74. data/lib/templates/puppet/default_profiles/base/security/ssh/Puppetfile +2 -0
  75. data/lib/templates/puppet/default_profiles/base/security/ssh/manifests/init.pp +30 -0
  76. data/lib/templates/puppet/default_profiles/base/security/sysctl/Puppetfile +2 -0
  77. data/lib/templates/puppet/default_profiles/base/security/sysctl/manifests/init.pp +20 -0
  78. data/lib/templates/puppet/default_profiles/base/users/ssh/Puppetfile +2 -0
  79. data/lib/templates/puppet/default_profiles/base/users/ssh/manifests/init.pp +47 -0
  80. data/lib/templates/puppet/default_profiles/base/users/users/Puppetfile +0 -0
  81. data/lib/templates/puppet/default_profiles/base/users/users/manifests/init.pp +18 -0
  82. data/lib/templates/puppet/default_roles/fundamental/manifests/init.pp +16 -0
  83. data/lib/templates/puppet/default_roles/security/manifests/init.pp +17 -0
  84. data/lib/templates/puppet/default_roles/users/manifests/init.pp +15 -0
  85. data/lib/templates/puppet/profiles/Puppetfile.erb +24 -0
  86. data/lib/templates/puppet/profiles/manifests/init.pp.erb +17 -0
  87. data/lib/templates/puppet/roles/manifests/init.pp.erb +14 -0
  88. data/lib/templates/puppet/step-0/Puppetfile.erb +5 -0
  89. data/lib/templates/puppet/step-0/hiera/data/common.yaml.erb +26 -0
  90. data/lib/templates/puppet/step-0/hiera/data/environment.yaml.erb +26 -0
  91. data/lib/templates/puppet/step-0/hiera/data/node.yaml.erb +26 -0
  92. data/lib/templates/puppet/step-0/hiera/hiera.yaml.erb +11 -0
  93. data/lib/templates/puppet/step-0/manifests/node.erb +5 -0
  94. data/lib/templates/puppet/step-0/manifests/site.pp.erb +15 -0
  95. data/lib/templates/puppet/step-0/modules/rbenv/AUTHORS +11 -0
  96. data/lib/templates/puppet/step-0/modules/rbenv/CHANGELOG.md +70 -0
  97. data/lib/templates/puppet/step-0/modules/rbenv/Gemfile +8 -0
  98. data/lib/templates/puppet/step-0/modules/rbenv/Gemfile.lock +28 -0
  99. data/lib/templates/puppet/step-0/modules/rbenv/Modulefile +7 -0
  100. data/lib/templates/puppet/step-0/modules/rbenv/README.md +173 -0
  101. data/lib/templates/puppet/step-0/modules/rbenv/Rakefile +22 -0
  102. data/lib/templates/puppet/step-0/modules/rbenv/TODO +10 -0
  103. data/lib/templates/puppet/step-0/modules/rbenv/bin/autospec +16 -0
  104. data/lib/templates/puppet/step-0/modules/rbenv/bin/facter +16 -0
  105. data/lib/templates/puppet/step-0/modules/rbenv/bin/filebucket +16 -0
  106. data/lib/templates/puppet/step-0/modules/rbenv/bin/hiera +16 -0
  107. data/lib/templates/puppet/step-0/modules/rbenv/bin/htmldiff +16 -0
  108. data/lib/templates/puppet/step-0/modules/rbenv/bin/ldiff +16 -0
  109. data/lib/templates/puppet/step-0/modules/rbenv/bin/pi +16 -0
  110. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppet +16 -0
  111. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppet-lint +16 -0
  112. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppet-module +16 -0
  113. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppetca +16 -0
  114. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppetd +16 -0
  115. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppetdoc +16 -0
  116. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppetmasterd +16 -0
  117. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppetqd +16 -0
  118. data/lib/templates/puppet/step-0/modules/rbenv/bin/puppetrun +16 -0
  119. data/lib/templates/puppet/step-0/modules/rbenv/bin/rake +16 -0
  120. data/lib/templates/puppet/step-0/modules/rbenv/bin/ralsh +16 -0
  121. data/lib/templates/puppet/step-0/modules/rbenv/bin/rspec +16 -0
  122. data/lib/templates/puppet/step-0/modules/rbenv/bin/rspec-puppet-init +16 -0
  123. data/lib/templates/puppet/step-0/modules/rbenv/lib/puppet/provider/rbenvgem/default.rb +50 -0
  124. data/lib/templates/puppet/step-0/modules/rbenv/lib/puppet/type/rbenvgem.rb +62 -0
  125. data/lib/templates/puppet/step-0/modules/rbenv/manifests/bundle.pp +36 -0
  126. data/lib/templates/puppet/step-0/modules/rbenv/manifests/client.pp +48 -0
  127. data/lib/templates/puppet/step-0/modules/rbenv/manifests/compile.pp +102 -0
  128. data/lib/templates/puppet/step-0/modules/rbenv/manifests/definition.pp +31 -0
  129. data/lib/templates/puppet/step-0/modules/rbenv/manifests/dependencies/centos.pp +25 -0
  130. data/lib/templates/puppet/step-0/modules/rbenv/manifests/dependencies/suse.pp +28 -0
  131. data/lib/templates/puppet/step-0/modules/rbenv/manifests/dependencies/ubuntu.pp +17 -0
  132. data/lib/templates/puppet/step-0/modules/rbenv/manifests/dependencies.pp +8 -0
  133. data/lib/templates/puppet/step-0/modules/rbenv/manifests/gem.pp +29 -0
  134. data/lib/templates/puppet/step-0/modules/rbenv/manifests/install.pp +55 -0
  135. data/lib/templates/puppet/step-0/modules/rbenv/manifests/plugin/rbenvvars.pp +16 -0
  136. data/lib/templates/puppet/step-0/modules/rbenv/manifests/plugin/rubybuild.pp +16 -0
  137. data/lib/templates/puppet/step-0/modules/rbenv/manifests/plugin.pp +40 -0
  138. data/lib/templates/puppet/step-0/modules/rbenv/metadata.json +109 -0
  139. data/lib/templates/puppet/step-0/modules/rbenv/templates/Gemfile.erb +5 -0
  140. data/lib/templates/puppet/step-0/modules/rbenv/templates/dot.rbenvrc.erb +8 -0
  141. data/lib/templates/puppet/step-0/modules/stdlib/CHANGELOG.md +418 -0
  142. data/lib/templates/puppet/step-0/modules/stdlib/CONTRIBUTING.md +65 -0
  143. data/lib/templates/puppet/step-0/modules/stdlib/Gemfile +33 -0
  144. data/lib/templates/puppet/step-0/modules/stdlib/Gemfile.lock +166 -0
  145. data/lib/templates/puppet/step-0/modules/stdlib/LICENSE +19 -0
  146. data/lib/templates/puppet/step-0/modules/stdlib/Modulefile +11 -0
  147. data/lib/templates/puppet/step-0/modules/stdlib/README.markdown +1304 -0
  148. data/lib/templates/puppet/step-0/modules/stdlib/README_DEVELOPER.markdown +35 -0
  149. data/lib/templates/puppet/step-0/modules/stdlib/README_SPECS.markdown +7 -0
  150. data/lib/templates/puppet/step-0/modules/stdlib/RELEASE_PROCESS.markdown +24 -0
  151. data/lib/templates/puppet/step-0/modules/stdlib/Rakefile +18 -0
  152. data/lib/templates/puppet/step-0/modules/stdlib/checksums.json +349 -0
  153. data/lib/templates/puppet/step-0/modules/stdlib/lib/facter/facter_dot_d.rb +202 -0
  154. data/lib/templates/puppet/step-0/modules/stdlib/lib/facter/pe_version.rb +53 -0
  155. data/lib/templates/puppet/step-0/modules/stdlib/lib/facter/puppet_vardir.rb +26 -0
  156. data/lib/templates/puppet/step-0/modules/stdlib/lib/facter/root_home.rb +32 -0
  157. data/lib/templates/puppet/step-0/modules/stdlib/lib/facter/util/puppet_settings.rb +21 -0
  158. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/abs.rb +36 -0
  159. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/any2array.rb +33 -0
  160. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/base64.rb +37 -0
  161. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/bool2num.rb +49 -0
  162. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/capitalize.rb +34 -0
  163. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/chomp.rb +35 -0
  164. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/chop.rb +37 -0
  165. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/concat.rb +41 -0
  166. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/count.rb +22 -0
  167. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/deep_merge.rb +44 -0
  168. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb +35 -0
  169. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/delete.rb +46 -0
  170. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/delete_at.rb +49 -0
  171. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/delete_undef_values.rb +34 -0
  172. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/delete_values.rb +26 -0
  173. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/difference.rb +36 -0
  174. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/dirname.rb +15 -0
  175. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/downcase.rb +33 -0
  176. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/empty.rb +28 -0
  177. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb +35 -0
  178. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb +45 -0
  179. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/flatten.rb +33 -0
  180. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/floor.rb +25 -0
  181. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb +46 -0
  182. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb +17 -0
  183. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/getparam.rb +35 -0
  184. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/getvar.rb +26 -0
  185. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/grep.rb +33 -0
  186. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb +52 -0
  187. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb +25 -0
  188. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb +25 -0
  189. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/has_key.rb +28 -0
  190. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/hash.rb +41 -0
  191. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/intersection.rb +34 -0
  192. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_array.rb +22 -0
  193. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_bool.rb +22 -0
  194. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb +50 -0
  195. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_float.rb +30 -0
  196. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb +26 -0
  197. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_hash.rb +22 -0
  198. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_integer.rb +45 -0
  199. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb +32 -0
  200. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb +27 -0
  201. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb +75 -0
  202. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/is_string.rb +26 -0
  203. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/join.rb +41 -0
  204. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb +47 -0
  205. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/keys.rb +26 -0
  206. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb +20 -0
  207. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/lstrip.rb +33 -0
  208. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/max.rb +21 -0
  209. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/member.rb +44 -0
  210. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/merge.rb +34 -0
  211. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/min.rb +21 -0
  212. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/num2bool.rb +43 -0
  213. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/parsejson.rb +24 -0
  214. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb +24 -0
  215. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/pick.rb +29 -0
  216. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/pick_default.rb +35 -0
  217. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/prefix.rb +45 -0
  218. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/range.rb +88 -0
  219. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/reject.rb +31 -0
  220. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/reverse.rb +28 -0
  221. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/rstrip.rb +32 -0
  222. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/shuffle.rb +46 -0
  223. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/size.rb +48 -0
  224. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/sort.rb +27 -0
  225. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/squeeze.rb +36 -0
  226. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/str2bool.rb +46 -0
  227. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb +32 -0
  228. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/strftime.rb +107 -0
  229. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/strip.rb +39 -0
  230. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/suffix.rb +45 -0
  231. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/swapcase.rb +39 -0
  232. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/time.rb +49 -0
  233. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb +28 -0
  234. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/type.rb +50 -0
  235. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/union.rb +34 -0
  236. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/unique.rb +51 -0
  237. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/upcase.rb +41 -0
  238. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/uriescape.rb +35 -0
  239. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb +56 -0
  240. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_array.rb +33 -0
  241. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb +81 -0
  242. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb +34 -0
  243. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb +48 -0
  244. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb +33 -0
  245. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_ipv4_address.rb +48 -0
  246. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_ipv6_address.rb +49 -0
  247. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_re.rb +40 -0
  248. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb +71 -0
  249. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/validate_string.rb +33 -0
  250. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/values.rb +39 -0
  251. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/values_at.rb +98 -0
  252. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/parser/functions/zip.rb +65 -0
  253. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/provider/file_line/ruby.rb +83 -0
  254. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/type/anchor.rb +46 -0
  255. data/lib/templates/puppet/step-0/modules/stdlib/lib/puppet/type/file_line.rb +79 -0
  256. data/lib/templates/puppet/step-0/modules/stdlib/manifests/init.pp +20 -0
  257. data/lib/templates/puppet/step-0/modules/stdlib/manifests/stages.pp +43 -0
  258. data/lib/templates/puppet/step-0/modules/stdlib/metadata.json +111 -0
  259. data/lib/templates/puppet/step-0/modules/sudo/.fixtures.yml +5 -0
  260. data/lib/templates/puppet/step-0/modules/sudo/.gemfile +14 -0
  261. data/lib/templates/puppet/step-0/modules/sudo/.gemfile.lock +43 -0
  262. data/lib/templates/puppet/step-0/modules/sudo/.travis.yml +34 -0
  263. data/lib/templates/puppet/step-0/modules/sudo/LICENSE +13 -0
  264. data/lib/templates/puppet/step-0/modules/sudo/Modulefile +9 -0
  265. data/lib/templates/puppet/step-0/modules/sudo/README.md +171 -0
  266. data/lib/templates/puppet/step-0/modules/sudo/Rakefile +1 -0
  267. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.aix +90 -0
  268. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.archlinux +90 -0
  269. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.deb +90 -0
  270. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.freebsd +98 -0
  271. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.omnios +90 -0
  272. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.rhel5 +97 -0
  273. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.rhel6 +115 -0
  274. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.solaris +90 -0
  275. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.suse +81 -0
  276. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.ubuntu +30 -0
  277. data/lib/templates/puppet/step-0/modules/sudo/files/sudoers.wheezy +17 -0
  278. data/lib/templates/puppet/step-0/modules/sudo/lib/augeas/lenses/fixedsudoers.aug +520 -0
  279. data/lib/templates/puppet/step-0/modules/sudo/manifests/allow.pp +76 -0
  280. data/lib/templates/puppet/step-0/modules/sudo/manifests/conf.pp +105 -0
  281. data/lib/templates/puppet/step-0/modules/sudo/manifests/configs.pp +24 -0
  282. data/lib/templates/puppet/step-0/modules/sudo/manifests/init.pp +151 -0
  283. data/lib/templates/puppet/step-0/modules/sudo/manifests/package/aix.pp +46 -0
  284. data/lib/templates/puppet/step-0/modules/sudo/manifests/package/solaris.pp +60 -0
  285. data/lib/templates/puppet/step-0/modules/sudo/manifests/package.pp +61 -0
  286. data/lib/templates/puppet/step-0/modules/sudo/manifests/params.pp +127 -0
  287. data/lib/templates/puppet/step-0/modules/sudo/metadata.json +59 -0
  288. data/lib/templates/puppet/step-0/modules/sudo/templates/users_groups.erb +9 -0
  289. data/lib/templates/puppet/step-0/modules/users/manifests/init.pp +15 -0
  290. data/lib/templates/puppet/step-0/modules/users/manifests/user.pp +50 -0
  291. data/lib/templates/puppet/step-1/Puppetfile.erb +5 -0
  292. data/lib/templates/puppet/step-1/hiera/data/common.yaml.erb +11 -0
  293. data/lib/templates/puppet/step-1/hiera/data/environment.yaml.erb +11 -0
  294. data/lib/templates/puppet/step-1/hiera/data/node.yaml.erb +11 -0
  295. data/lib/templates/puppet/step-1/hiera/hiera.yaml.erb +11 -0
  296. data/lib/templates/puppet/step-1/manifests/node.erb +5 -0
  297. data/lib/templates/puppet/step-1/manifests/site.pp.erb +15 -0
  298. data/lib/templates/puppet/step-1/modules/users/manifests/init.pp +15 -0
  299. data/lib/templates/puppet/step-1/modules/users/manifests/user.pp +49 -0
  300. data/lib/templates/puppet/step-2/Puppetfile.erb +5 -0
  301. data/lib/templates/puppet/step-2/hiera/data/common.yaml.erb +1 -0
  302. data/lib/templates/puppet/step-2/hiera/data/environment.yaml.erb +1 -0
  303. data/lib/templates/puppet/step-2/hiera/data/node.yaml.erb +1 -0
  304. data/lib/templates/puppet/step-2/hiera/hiera.yaml.erb +11 -0
  305. data/lib/templates/puppet/step-2/manifests/node.erb +3 -0
  306. data/lib/templates/puppet/step-2/manifests/site.pp.erb +10 -0
  307. data/lib/templates/puppet/step-3/Puppetfile.erb +5 -0
  308. data/lib/templates/puppet/step-3/hiera/data/common.yaml.erb +99 -0
  309. data/lib/templates/puppet/step-3/hiera/data/environment.yaml.erb +99 -0
  310. data/lib/templates/puppet/step-3/hiera/data/node.yaml.erb +99 -0
  311. data/lib/templates/puppet/step-3/hiera/hiera.yaml.erb +11 -0
  312. data/lib/templates/puppet/step-3/manifests/node.erb +5 -0
  313. data/lib/templates/puppet/step-3/manifests/site.pp.erb +15 -0
  314. data/spec/environment_spec.rb +82 -0
  315. data/spec/factories/environment.rb +20 -0
  316. data/spec/factories/node.rb +22 -0
  317. data/spec/factories/profile.rb +10 -0
  318. data/spec/factories/project.rb +17 -0
  319. data/spec/factories/provision.rb +13 -0
  320. data/spec/factories/role.rb +9 -0
  321. data/spec/fixtures/Capfile.test +2 -0
  322. data/spec/fixtures/Gemfile.test +5 -0
  323. data/spec/fixtures/config/deploy/environment.test +35 -0
  324. data/spec/fixtures/config/deploy/production.test +35 -0
  325. data/spec/fixtures/config/deploy/staging.test +35 -0
  326. data/spec/fixtures/config/deploy/vagrant.test +37 -0
  327. data/spec/fixtures/config/deploy.test +120 -0
  328. data/spec/fixtures/dot_bebox.test.erb +4 -0
  329. data/spec/fixtures/dot_gitignore.test +8 -0
  330. data/spec/fixtures/node/Vagrantfile.test.erb +18 -0
  331. data/spec/fixtures/node/node_0.test.erb +3 -0
  332. data/spec/fixtures/node/prepared_node_0.test.erb +4 -0
  333. data/spec/fixtures/node/provisioned_node_0.test.erb +4 -0
  334. data/spec/fixtures/node/vagrant_deploy.test +38 -0
  335. data/spec/fixtures/puppet/hiera/data/node0.server1.test.yaml.test +4 -0
  336. data/spec/fixtures/puppet/profiles/test/profile_0/Puppetfile.test +24 -0
  337. data/spec/fixtures/puppet/profiles/test/profile_0/Puppetfile_with_modules.test +20 -0
  338. data/spec/fixtures/puppet/profiles/test/profile_0/manifests/init.pp.test +17 -0
  339. data/spec/fixtures/puppet/profiles/test/profile_0/manifests/init_with_content.pp.test +22 -0
  340. data/spec/fixtures/puppet/roles/manifests/init.pp.test +14 -0
  341. data/spec/fixtures/puppet/steps/step-0/hiera/data/common.yaml.test +26 -0
  342. data/spec/fixtures/puppet/steps/step-0/hiera/data/node0.server1.test.yaml.test +0 -0
  343. data/spec/fixtures/puppet/steps/step-0/hiera/data/pname_env.yaml.test +26 -0
  344. data/spec/fixtures/puppet/steps/step-0/hiera/data/production.yaml.test +0 -0
  345. data/spec/fixtures/puppet/steps/step-0/hiera/data/staging.yaml.test +0 -0
  346. data/spec/fixtures/puppet/steps/step-0/hiera/data/vagrant.yaml.test +0 -0
  347. data/spec/fixtures/puppet/steps/step-0/hiera/hiera.yaml.test +11 -0
  348. data/spec/fixtures/puppet/steps/step-0/manifests/site.pp.test +10 -0
  349. data/spec/fixtures/puppet/steps/step-0/manifests/site_with_node.pp.test +15 -0
  350. data/spec/fixtures/puppet/steps/step-1/hiera/data/common.yaml.test +11 -0
  351. data/spec/fixtures/puppet/steps/step-1/hiera/data/node0.server1.test.yaml.test +0 -0
  352. data/spec/fixtures/puppet/steps/step-1/hiera/data/pname_env.yaml.test +11 -0
  353. data/spec/fixtures/puppet/steps/step-1/hiera/data/production.yaml.test +0 -0
  354. data/spec/fixtures/puppet/steps/step-1/hiera/data/staging.yaml.test +0 -0
  355. data/spec/fixtures/puppet/steps/step-1/hiera/data/vagrant.yaml.test +0 -0
  356. data/spec/fixtures/puppet/steps/step-1/hiera/hiera.yaml.test +11 -0
  357. data/spec/fixtures/puppet/steps/step-1/manifests/site.pp.test +10 -0
  358. data/spec/fixtures/puppet/steps/step-1/manifests/site_with_node.pp.test +15 -0
  359. data/spec/fixtures/puppet/steps/step-2/Puppetfile.test +6 -0
  360. data/spec/fixtures/puppet/steps/step-2/hiera/data/common.yaml.test +1 -0
  361. data/spec/fixtures/puppet/steps/step-2/hiera/data/node0.server1.test.yaml.test +1 -0
  362. data/spec/fixtures/puppet/steps/step-2/hiera/data/pname_env.yaml.test +1 -0
  363. data/spec/fixtures/puppet/steps/step-2/hiera/data/production.yaml.test +1 -0
  364. data/spec/fixtures/puppet/steps/step-2/hiera/data/staging.yaml.test +1 -0
  365. data/spec/fixtures/puppet/steps/step-2/hiera/data/vagrant.yaml.test +1 -0
  366. data/spec/fixtures/puppet/steps/step-2/hiera/hiera.yaml.test +11 -0
  367. data/spec/fixtures/puppet/steps/step-2/manifests/site.pp.test +10 -0
  368. data/spec/fixtures/puppet/steps/step-2/manifests/site_with_node.pp.test +13 -0
  369. data/spec/fixtures/puppet/steps/step-2/manifests/site_with_node_role_association.pp.test +16 -0
  370. data/spec/fixtures/puppet/steps/step-2/modules/profiles/manifests/test/profile_0.pp.test +17 -0
  371. data/spec/fixtures/puppet/steps/step-2/modules/roles/manifests/role_0.pp.test +16 -0
  372. data/spec/fixtures/puppet/steps/step-3/hiera/data/common.yaml.test +99 -0
  373. data/spec/fixtures/puppet/steps/step-3/hiera/data/node0.server1.test.yaml.test +1 -0
  374. data/spec/fixtures/puppet/steps/step-3/hiera/data/pname_env.yaml.test +99 -0
  375. data/spec/fixtures/puppet/steps/step-3/hiera/data/production.yaml.test +1 -0
  376. data/spec/fixtures/puppet/steps/step-3/hiera/data/staging.yaml.test +1 -0
  377. data/spec/fixtures/puppet/steps/step-3/hiera/data/vagrant.yaml.test +1 -0
  378. data/spec/fixtures/puppet/steps/step-3/hiera/hiera.yaml.test +11 -0
  379. data/spec/fixtures/puppet/steps/step-3/manifests/site.pp.test +10 -0
  380. data/spec/fixtures/puppet/steps/step-3/manifests/site_with_node.pp.test +15 -0
  381. data/spec/fixtures/puppet/ubuntu_dependencies.test +10 -0
  382. data/spec/node0.server1.test/prepare_phase_spec.rb +53 -0
  383. data/spec/node0.server1.test/provision_step_0_spec.rb +46 -0
  384. data/spec/node0.server1.test/provision_step_1_spec.rb +41 -0
  385. data/spec/node0.server1.test/provision_step_2_spec.rb +79 -0
  386. data/spec/node0.server1.test/provision_step_3_spec.rb +76 -0
  387. data/spec/node_role_spec.rb +20 -0
  388. data/spec/node_spec.rb +71 -0
  389. data/spec/node_wizard_spec.rb +22 -0
  390. data/spec/ordered_phases_spec.rb +55 -0
  391. data/spec/pre_prepare_spec.rb +78 -0
  392. data/spec/pre_provision_steps_spec.rb +40 -0
  393. data/spec/profile_spec.rb +70 -0
  394. data/spec/project_spec.rb +195 -0
  395. data/spec/project_wizard_spec.rb +51 -0
  396. data/spec/puppet_spec_helper.rb +15 -0
  397. data/spec/role_profiles_spec.rb +40 -0
  398. data/spec/role_spec.rb +56 -0
  399. data/spec/spec_helper.rb +37 -0
  400. data/spec/support/config_specs.yaml.example +2 -0
  401. data/spec/vagrant_spec_helper.rb +15 -0
  402. metadata +625 -0
@@ -0,0 +1,257 @@
1
+ require 'tilt'
2
+
3
+ module Bebox
4
+
5
+ PROVISION_STEPS = %w{step-0 step-1 step-2 step-3}
6
+ PROVISION_STEP_NAMES = %w{0-fundamental 1-users 2-services 3-security}
7
+ RESERVED_WORDS = %w{and case class default define else elsif false if in import inherits node or true undef unless main settings}
8
+
9
+ class Provision
10
+
11
+ attr_accessor :environment, :project_root, :node, :step, :started_at, :finished_at
12
+
13
+ def initialize(project_root, environment, node, step)
14
+ self.project_root = project_root
15
+ self.environment = environment
16
+ self.node = node
17
+ self.step = step
18
+ end
19
+
20
+ # Puppet apply Fundamental step
21
+ def apply
22
+ started_at = DateTime.now.to_s
23
+ # Check if a Puppetfile is neccesary for use/not use librarian-puppet
24
+ check_puppetfile_content
25
+ # Copy static modules that are not downloaded by librarian-puppet
26
+ copy_static_modules
27
+ # Apply step and if the process is succesful create the checkpoint.
28
+ process_status = apply_step
29
+ create_step_checkpoint(started_at) if process_status.success?
30
+ process_status
31
+ end
32
+
33
+ # Check if it's necessary a Puppetfile accord to it's content
34
+ def check_puppetfile_content
35
+ puppetfile_content = File.read("#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/Puppetfile").strip
36
+ `rm "#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/Puppetfile"` if puppetfile_content.scan(/^\s*(mod\s*.+?)$/).flatten.empty?
37
+ end
38
+
39
+ # Copy the static modules to the step-N modules path
40
+ def copy_static_modules
41
+ `cp -R #{Bebox::Provision::templates_path}/puppet/#{self.step}/modules/* #{self.project_root}/puppet/steps/#{Bebox::Provision.step_name(self.step)}/modules/`
42
+ end
43
+
44
+ # Generate the hiera data for step from the template
45
+ def generate_hiera
46
+ ssh_key = Bebox::Project.public_ssh_key_from_file(self.project_root, self.environment)
47
+ project_name = Bebox::Project.shortname_from_file(self.project_root)
48
+ hiera_template = Tilt::ERBTemplate.new("#{Bebox::Provision::templates_path}/puppet/#{self.step}/hiera/hiera.yaml.erb")
49
+ File.open("#{self.project_root}/puppet/steps/#{Bebox::Provision.step_name(self.step)}/hiera/hiera.yaml", 'w') do |f|
50
+ f.write hiera_template.render(nil, :step_dir => Bebox::Provision.step_name(self.step))
51
+ end
52
+ common_hiera_template = Tilt::ERBTemplate.new("#{Bebox::Provision::templates_path}/puppet/#{self.step}/hiera/data/common_apply.yaml.erb")
53
+ File.open("#{self.project_root}/puppet/steps/#{Bebox::Provision.step_name(self.step)}/hiera/data/common.yaml", 'w') do |f|
54
+ f.write common_hiera_template.render(nil, :ssh_key => ssh_key, :project_name => project_name)
55
+ end
56
+ end
57
+
58
+ # Generate the site.pp manifests file for step
59
+ def self.generate_manifests(project_root, step, nodes)
60
+ manifest_template = Tilt::ERBTemplate.new("#{Bebox::Provision::templates_path}/puppet/#{step}/manifests/site_apply.pp.erb", :trim => true)
61
+ File.open("#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/manifests/site.pp", 'w') do |f|
62
+ f.write manifest_template.render(nil, :nodes => nodes)
63
+ end
64
+ end
65
+
66
+ # Generate the hiera templates for each step
67
+ def self.generate_hiera_for_steps(project_root, template_file, filename, options)
68
+ Bebox::PROVISION_STEPS.each do |step|
69
+ step_dir = Bebox::Provision.step_name(step)
70
+ hiera_template = Tilt::ERBTemplate.new("#{Bebox::Provision::templates_path}/puppet/#{step}/hiera/data/#{template_file}")
71
+ File.open("#{project_root}/puppet/steps/#{step_dir}/hiera/data/#{filename}.yaml", 'w') do |f|
72
+ f.write hiera_template.render(nil, options)
73
+ end
74
+ end
75
+ end
76
+
77
+ # Generate the roles and profiles modules for the step
78
+ def self.generate_roles_and_profiles(project_root, step, role, profiles)
79
+ # Re-create the roles and profiles puppet module directories
80
+ `rm -rf #{project_root}/puppet/steps/#{step_name(step)}/modules/{roles,profiles}`
81
+ `mkdir -p #{project_root}/puppet/steps/#{step_name(step)}/modules/{roles,profiles}/manifests`
82
+ # Copy role to puppet roles module
83
+ `cp #{project_root}/puppet/roles/#{role}/manifests/init.pp #{project_root}/puppet/steps/#{step_name(step)}/modules/roles/manifests/#{role}.pp`
84
+ # Copy profiles to puppet profiles module
85
+ profiles.each do |profile|
86
+ profile_tree = profile.gsub('::','/')
87
+ profile_tree_parent = profile_tree.split('/')[0...-1].join('/')
88
+ `mkdir -p #{project_root}/puppet/steps/#{step_name(step)}/modules/profiles/manifests/#{profile_tree_parent}`
89
+ `cp #{project_root}/puppet/profiles/#{profile_tree}/manifests/init.pp #{project_root}/puppet/steps/#{step_name(step)}/modules/profiles/manifests/#{profile_tree}.pp`
90
+ end
91
+ end
92
+
93
+ # Generate the Puppetfile from the role-profiles partial puppetfiles
94
+ def self.generate_puppetfile(project_root, step, profiles)
95
+ modules = []
96
+ puppetfile_path = "#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/Puppetfile"
97
+ profiles.each do |profile|
98
+ profile_puppetfile_path = "#{project_root}/puppet/profiles/#{profile.gsub('::','/')}/Puppetfile"
99
+ puppetfile_content = File.read(profile_puppetfile_path)
100
+ modules << puppetfile_content.scan(/^\s*(mod\s*.+?)$/).uniq
101
+ end
102
+ puppetfile_template = Tilt::ERBTemplate.new("#{Bebox::Provision::templates_path}/puppet/#{step}/Puppetfile.erb", :trim => true)
103
+ File.open("#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/Puppetfile", 'w') do |f|
104
+ f.write puppetfile_template.render(nil, :profile_modules => modules.flatten)
105
+ end
106
+ end
107
+
108
+ # Get the role name associated with a node
109
+ def self.role_from_node(project_root, step, node)
110
+ manifest_path = "#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/manifests/site.pp"
111
+ manifest_content = File.read(manifest_path)
112
+ matching_nodes = manifest_content.match(/^\s*node\s+#{node}\s*({.*?}\s*)/m)
113
+ unless matching_nodes.nil?
114
+ matching_role = matching_nodes[0].strip.match(/roles::(.+?$)/)
115
+ role = matching_role[1] unless matching_role.nil?
116
+ end
117
+ role
118
+ end
119
+
120
+ # Get the profiles names array associated with a role
121
+ def self.profiles_from_role(project_root, role_name)
122
+ profiles = []
123
+ role_path = "#{project_root}/puppet/roles/#{role_name}/manifests/init.pp"
124
+ role_content = File.read(role_path)
125
+ matching_roles = role_content.match(/^\s*class\s+roles::#{role_name}\s*({.*?}\s*)/m)
126
+ profiles = matching_roles[0].strip.scan(/profiles::(.+?$)/).flatten unless matching_roles.nil?
127
+ profiles
128
+ end
129
+
130
+ # Set a role for a node in the step-2 manifests file
131
+ def self.associate_node_role(project_root, environment, node_name, role_name)
132
+ # Create the manifests site.pp file for step-2 if not exist
133
+ unless Bebox::Provision.manifests_exists?(project_root, 'step-2')
134
+ nodes = Bebox::Node.nodes_in_environment(project_root, environment, 'nodes')
135
+ Bebox::Provision.generate_manifests(project_root, self.step, nodes)
136
+ end
137
+ # Set the role for a node
138
+ Bebox::Provision.remove_role(project_root, node_name, 'step-2')
139
+ Bebox::Provision.add_role(project_root, node_name, role_name)
140
+ end
141
+
142
+ # Add a node to site.pp
143
+ def self.add_node_to_step_manifests(project_root, node)
144
+ Bebox::PROVISION_STEPS.each do |step|
145
+ manifest_node_template = Tilt::ERBTemplate.new("#{Bebox::Provision::templates_path}/puppet/#{step}/manifests/node.erb", :trim => true)
146
+ manifest_node = manifest_node_template.render(nil, :node => node)
147
+ Bebox::Provision.remove_node(project_root, node.hostname, step)
148
+ manifest_path = "#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/manifests/site.pp"
149
+ content = File.read(manifest_path)
150
+ content += "\n#{manifest_node}\n"
151
+ File.open(manifest_path, 'wb') { |file| file.write(content) }
152
+ end
153
+ end
154
+
155
+ # Remove hiera data file for node
156
+ def self.remove_hiera_for_steps(project_root, node_name)
157
+ Bebox::PROVISION_STEP_NAMES.each do |step|
158
+ `cd #{project_root} && rm -rf #{project_root}/puppet/steps/#{step}/hiera/data/#{node_name}.yaml`
159
+ end
160
+ end
161
+
162
+ # Remove node in manifests file for each step
163
+ def self.remove_node_for_steps(project_root, node_name)
164
+ Bebox::PROVISION_STEPS.each do |step|
165
+ Bebox::Provision.remove_node(project_root, node_name, step)
166
+ end
167
+ end
168
+
169
+ # Add a role to a node
170
+ def self.add_role(project_root, node_name, role_name)
171
+ tempfile_path = "#{project_root}/puppet/steps/#{Bebox::Provision.step_name('step-2')}/manifests/site.pp.tmp"
172
+ manifest_path = "#{project_root}/puppet/steps/#{Bebox::Provision.step_name('step-2')}/manifests/site.pp"
173
+ tempfile = File.open(tempfile_path, 'w')
174
+ manifest_file = File.new(manifest_path)
175
+ manifest_file.each do |line|
176
+ line << "\n include roles::#{role_name}\n" if (line =~ /^\s*node\s+#{node_name}\s+{\s*$/)
177
+ tempfile << line
178
+ end
179
+ manifest_file.close
180
+ tempfile.close
181
+ FileUtils.mv(tempfile_path, manifest_path)
182
+ end
183
+
184
+ # Remove the current role in a node
185
+ def self.remove_node(project_root, node_name, step)
186
+ manifest_path = "#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/manifests/site.pp"
187
+ regexp = /^\s*node\s+#{node_name}\s*({.*?}\s*)/m
188
+ content = File.read(manifest_path).sub(regexp, '')
189
+ File.open(manifest_path, 'wb') { |file| file.write(content) }
190
+ end
191
+
192
+ # Remove the current role in a node
193
+ def self.remove_role(project_root, node_name, step)
194
+ manifest_path = "#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/manifests/site.pp"
195
+ regexp = /^\s*node\s+#{node_name}\s*({.*?}\s*)/m
196
+ content = File.read(manifest_path).sub(regexp, "\nnode #{node_name} {\n\n}\n\n")
197
+ File.open(manifest_path, 'wb') { |file| file.write(content) }
198
+ end
199
+
200
+ # Check if a manifests for a step exist
201
+ def self.manifests_exists?(project_root, step)
202
+ File.exist?("#{project_root}/puppet/steps/#{Bebox::Provision.step_name(step)}/manifests/site.pp")
203
+ end
204
+
205
+ # Apply step via capistrano in the machine
206
+ def apply_step
207
+ # Create deploy directories
208
+ cap 'deploy:setup'
209
+ # Deploy the configured step
210
+ $?.success? ? (cap 'deploy') : (return $?)
211
+ # Download dynamic step modules through librarian-puppet
212
+ $?.success? ? (cap 'puppet:bundle_modules') : (return $?)
213
+ # Install the step provision through puppet
214
+ $?.success? ? (cap 'puppet:apply') : (return $?)
215
+ $?
216
+ end
217
+
218
+ # Executes capistrano commands
219
+ def cap(command)
220
+ `cd #{self.project_root} && BUNDLE_GEMFILE=Gemfile bundle exec cap #{self.environment} #{command} -S phase='#{self.step}' -S step_dir='#{step_name}' HOSTS=#{self.node.hostname}`
221
+ end
222
+
223
+ # Create checkpoint for step
224
+ def create_step_checkpoint(started_at)
225
+ self.node.started_at = started_at
226
+ self.node.finished_at = DateTime.now.to_s
227
+ checkpoint_template = Tilt::ERBTemplate.new("#{Bebox::Provision::templates_path}/node/provisioned_node.yml.erb")
228
+ File.open("#{self.project_root}/.checkpoints/environments/#{self.environment}/steps/#{self.step}/#{self.node.hostname}.yml", 'w') do |f|
229
+ f.write checkpoint_template.render(nil, :node => self.node)
230
+ end
231
+ end
232
+
233
+ # Get the templates path inside the gem
234
+ def self.templates_path
235
+ File.join((File.expand_path '..', File.dirname(__FILE__)), 'templates')
236
+ end
237
+
238
+ # Translate step name to directory name
239
+ def step_name
240
+ Bebox::Provision.step_name(self.step)
241
+ end
242
+
243
+ # Translate step name to directory name
244
+ def self.step_name(step)
245
+ case step
246
+ when 'step-0'
247
+ '0-fundamental'
248
+ when 'step-1'
249
+ '1-users'
250
+ when 'step-2'
251
+ '2-services'
252
+ when 'step-3'
253
+ '3-security'
254
+ end
255
+ end
256
+ end
257
+ end
data/lib/bebox/role.rb ADDED
@@ -0,0 +1,103 @@
1
+ require 'tilt'
2
+
3
+ module Bebox
4
+ class Role
5
+
6
+ attr_accessor :project_root, :name
7
+
8
+ def initialize(name, project_root)
9
+ self.project_root = project_root
10
+ self.name = name
11
+ end
12
+
13
+ # Create all files and directories related to a role
14
+ def create
15
+ create_role_directory
16
+ generate_manifests_file
17
+ end
18
+
19
+ # Delete all files and directories related to a role
20
+ def remove
21
+ `cd #{self.project_root} && rm -r puppet/roles/#{self.name}`
22
+ end
23
+
24
+ # Lists existing roles
25
+ def self.list(project_root)
26
+ Dir["#{project_root}/puppet/roles/*"].map { |f| File.basename(f) }
27
+ end
28
+
29
+ # Create the directories for the role
30
+ def create_role_directory
31
+ `cd #{self.project_root} && mkdir -p puppet/roles/#{self.name}/manifests`
32
+ end
33
+
34
+ # Generate the manifests init.pp file
35
+ def generate_manifests_file
36
+ manifests_template = Tilt::ERBTemplate.new("#{templates_path}/puppet/roles/manifests/init.pp.erb")
37
+ File.open("#{self.path}/manifests/init.pp", 'w') do |f|
38
+ f.write manifests_template.render(nil, :role => self)
39
+ end
40
+ end
41
+
42
+ # Path to the templates directory in the gem
43
+ def templates_path
44
+ File.join((File.expand_path '..', File.dirname(__FILE__)), 'templates')
45
+ end
46
+
47
+ # Path to the role directory in the project
48
+ def path
49
+ "#{self.project_root}/puppet/roles/#{self.name}"
50
+ end
51
+
52
+ # Counts existing roles
53
+ def self.roles_count(project_root)
54
+ Bebox::Role.list(project_root).count
55
+ end
56
+
57
+ # Add a profile to a role
58
+ def self.add_profile(project_root, role, profile)
59
+ tempfile_path = "#{project_root}/puppet/roles/#{role}/manifests/init.pp.tmp"
60
+ manifest_path = "#{project_root}/puppet/roles/#{role}/manifests/init.pp"
61
+ tempfile = File.open(tempfile_path, 'w')
62
+ manifest_file = File.new(manifest_path)
63
+ manifest_file.each do |line|
64
+ line << "\n\tinclude profiles::#{profile.gsub('/','::')}\n" if line.start_with?('class')
65
+ tempfile << line
66
+ end
67
+ manifest_file.close
68
+ tempfile.close
69
+ FileUtils.mv(tempfile_path, manifest_path)
70
+ end
71
+
72
+ # Remove a profile in a role
73
+ def self.remove_profile(project_root, role, profile)
74
+ manifest_path = "#{project_root}/puppet/roles/#{role}/manifests/init.pp"
75
+ regexp = /^\s*include\s+profiles::#{profile.gsub('/','::')}\s*$/
76
+ content = File.read(manifest_path).gsub(regexp, '')
77
+ File.open(manifest_path, 'wb') { |file| file.write(content) }
78
+ end
79
+
80
+ # List profiles in a role
81
+ def self.list_profiles(project_root, role)
82
+ profiles = []
83
+ File.readlines("#{project_root}/puppet/roles/#{role}/manifests/init.pp").each do |line|
84
+ row = line.strip
85
+ next if row.start_with?('#')
86
+ profiles << row.split('::').drop(1).join('/') if row.start_with?('include')
87
+ end
88
+ profiles
89
+ end
90
+
91
+ # Check if a profile is defined in a role
92
+ def self.profile_in_role?(project_root, role, profile)
93
+ role_profiles = Bebox::Role.list_profiles(project_root, role)
94
+ role_profiles.include?(profile) ? true : false
95
+ end
96
+
97
+ # Check if the role has a valid name
98
+ def self.valid_name?(name)
99
+ valid_name = (name =~ /\A[a-z][a-z0-9_]*\Z/).nil? ? false : true
100
+ valid_name && !Bebox::RESERVED_WORDS.include?(name)
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,3 @@
1
+ module Bebox
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,45 @@
1
+ module Bebox
2
+ class EnvironmentWizard
3
+ include Bebox::Logger
4
+ # Create a new environment
5
+ def create_new_environment(project_root, environment_name)
6
+ # Check if the environment exist
7
+ return error("The '#{environment_name}' environment already exist!.") if Bebox::Environment.environment_exists?(project_root, environment_name)
8
+ # Environment creation
9
+ environment = Bebox::Environment.new(environment_name, project_root)
10
+ environment.create
11
+ ok 'Environment created!.'
12
+ end
13
+
14
+ # Removes an existing environment
15
+ def remove_environment(project_root, environment_name)
16
+ # Check if the environment exist
17
+ return error("The '#{environment_name}' environment do not exist!.") unless Bebox::Environment.environment_exists?(project_root, environment_name)
18
+ # Confirm deletion
19
+ return warn('No changes were made.') unless confirm_environment_deletion?
20
+ # Environment deletion
21
+ environment = Bebox::Environment.new(environment_name, project_root)
22
+ environment.remove
23
+ ok 'Environment removed!.'
24
+ end
25
+
26
+ # Ask for confirmation of environment deletion
27
+ def confirm_environment_deletion?
28
+ quest 'Are you sure that you want to delete the environment?'
29
+ response = ask(highline_quest('(y/n)')) do |q|
30
+ q.default = "n"
31
+ end
32
+ return response == 'y' ? true : false
33
+ end
34
+
35
+ # Asks to choose an existing environment
36
+ def choose_environment(environments)
37
+ choose do |menu|
38
+ menu.header = title('Choose an existing environment:')
39
+ environments.each do |box|
40
+ menu.choice(box.split('/').last)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,163 @@
1
+ module Bebox
2
+ class NodeWizard
3
+ include Bebox::Logger
4
+ # Create a new node
5
+ def create_new_node(project_root, environment)
6
+ # Ask the hostname for node
7
+ hostname = ask_not_existing_hostname(project_root, environment)
8
+ # Ask IP for node
9
+ ip = ask_ip(environment)
10
+ # Node creation
11
+ node = Bebox::Node.new(environment, project_root, hostname, ip)
12
+ node.create
13
+ ok 'Node created!.'
14
+ end
15
+
16
+ # Removes an existing node
17
+ def remove_node(project_root, environment, hostname)
18
+ # Ask for a node to remove
19
+ nodes = Bebox::Node.list(project_root, environment, 'nodes')
20
+ if nodes.count > 0
21
+ hostname = choose_node(nodes, 'Choose the node to remove:')
22
+ else
23
+ return error "There are no nodes in the '#{environment}' environment to remove. No changes were made."
24
+ end
25
+ # Ask for deletion confirmation
26
+ return warn('No changes were made.') unless confirm_node_deletion?
27
+ # Node deletion
28
+ node = Bebox::Node.new(environment, project_root, hostname, nil)
29
+ node.remove
30
+ ok 'Node removed!.'
31
+ end
32
+
33
+ # Associate a role with a node in a environment
34
+ def set_role(project_root, environment)
35
+ roles = Bebox::Role.list(project_root)
36
+ nodes = Bebox::Node.list(project_root, environment, 'nodes')
37
+ node = choose_node(nodes, 'Choose an existing node:')
38
+ require 'bebox/wizards/role_wizard'
39
+ role = Bebox::RoleWizard.new.choose_role(roles, 'Choose an existing role:')
40
+ Bebox::Provision.associate_node_role(project_root, environment, node, role)
41
+ ok 'Role associated to node!.'
42
+ end
43
+
44
+ # Prepare the nodes in a environment
45
+ def prepare(project_root, environment)
46
+ # Check already prepared nodes
47
+ nodes_to_prepare = check_nodes_to_prepare(project_root, environment)
48
+ # Output the nodes to be prepared
49
+ if nodes_to_prepare.count > 0
50
+ title 'Preparing nodes:'
51
+ nodes_to_prepare.each{|node| msg(node.hostname)}
52
+ linebreak
53
+ # For all environments regenerate the deploy file
54
+ Bebox::Node.regenerate_deploy_file(project_root, environment, nodes_to_prepare)
55
+ # If environment is 'vagrant' Prepare and Up the machines
56
+ if environment == 'vagrant'
57
+ Bebox::Node.generate_vagrantfile(project_root, nodes_to_prepare)
58
+ nodes_to_prepare.each{|node| node.prepare_vagrant}
59
+ Bebox::Node.up_vagrant_nodes(project_root)
60
+ end
61
+ # For all the environments do the preparation
62
+ nodes_to_prepare.each do |node|
63
+ node.prepare
64
+ ok 'Node prepared!.'
65
+ end
66
+ else
67
+ warn 'There are no nodes to prepare. No changes were made.'
68
+ end
69
+ end
70
+
71
+ # Check the nodes already prepared and ask confirmation to re-do-it
72
+ def check_nodes_to_prepare(project_root, environment)
73
+ nodes_to_prepare = []
74
+ nodes = Bebox::Node.nodes_in_environment(project_root, environment, 'nodes')
75
+ prepared_nodes = Bebox::Node.list(project_root, environment, 'prepared_nodes')
76
+ nodes.each do |node|
77
+ if prepared_nodes.include?(node.hostname)
78
+ nodes_to_prepare << node if confirm_node_preparation?(node)
79
+ else
80
+ nodes_to_prepare << node
81
+ end
82
+ end
83
+ nodes_to_prepare
84
+ end
85
+
86
+ # Check if there's an existing node in a environment
87
+ def node_exists?(project_root, environment, node_name)
88
+ File.exists?("#{project_root}/.checkpoints/environments/#{environment}/nodes/#{node_name}.yml")
89
+ end
90
+
91
+ # Ask for confirmation of node preparation
92
+ def confirm_node_preparation?(node)
93
+ checkpoint_status = "(start: #{node.checkpoint_parameter_from_file('prepared_nodes', 'started_at')} - end: #{node.checkpoint_parameter_from_file('prepared_nodes', 'finished_at')})"
94
+ quest "The node '#{node.hostname}' was already prepared #{checkpoint_status}.\nDo you want to re-prepare it?"
95
+ response = ask(highline_quest('(y/n)')) do |q|
96
+ q.default = "n"
97
+ end
98
+ return response == 'y' ? true : false
99
+ end
100
+
101
+ # Ask for confirmation of node deletion
102
+ def confirm_node_deletion?
103
+ quest 'Are you sure that you want to delete the node?'
104
+ response = ask(highline_quest('(y/n)')) do |q|
105
+ q.default = "n"
106
+ end
107
+ return response == 'y' ? true : false
108
+ end
109
+
110
+ # Asks to choose an existing node
111
+ def choose_node(nodes, question)
112
+ choose do |menu|
113
+ menu.header = title(question)
114
+ nodes.each do |box|
115
+ menu.choice(box.split('/').last)
116
+ end
117
+ end
118
+ end
119
+
120
+ # Keep asking for a hostname that not exist
121
+ def ask_not_existing_hostname(project_root, environment)
122
+ hostname = ask_hostname(project_root, environment)
123
+ # Check if the node not exist
124
+ if node_exists?(project_root, environment, hostname)
125
+ error 'A hostname with that name already exist. Try a new one.'
126
+ ask_hostname(project_root, environment)
127
+ else
128
+ return hostname
129
+ end
130
+ end
131
+
132
+ # Ask for the hostname until is valid
133
+ def ask_hostname(project_root, environment)
134
+ ask(highline_quest('Write the hostname for the node:')) do |q|
135
+ q.validate = /\.(.*)/
136
+ q.responses[:not_valid] = highline_warn('Enter valid hostname. Ex. host.server1.com')
137
+ end
138
+ end
139
+
140
+ # Ask for the ip until is valid
141
+ def ask_ip(environment)
142
+ ip = ask(highline_quest('Write the IP address for the node:')) do |q|
143
+ q.validate = /\.(.*)/
144
+ q.responses[:not_valid] = highline_warn('Enter a valid IP address. Ex. 192.168.0.50')
145
+ end
146
+ # If the environment is not vagrant don't check ip free
147
+ return ip if environment != 'vagrant'
148
+ # Check if the ip address is free
149
+ if free_ip?(ip)
150
+ return ip
151
+ else
152
+ error 'The IP address is not free. Try a new one.'
153
+ ask_ip(environment)
154
+ end
155
+ end
156
+
157
+ # Validate if the IP address is free
158
+ def free_ip?(ip)
159
+ `ping -q -c 1 -W 3000 #{ip}`
160
+ ($?.exitstatus == 0) ? false : true
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,91 @@
1
+ require 'bebox/profile'
2
+
3
+ module Bebox
4
+ class ProfileWizard
5
+ include Bebox::Logger
6
+ # Create a new profile
7
+ def create_new_profile(project_root, profile_name, profile_base_path)
8
+ # Check if the profile name is valid
9
+ return error "The profile name can only contain:\n
10
+ \n* Lowercase letters
11
+ \n* Numbers
12
+ \n* Underscores
13
+ \n* Must begin with an Lowercase letter
14
+ \n* Can not be any of: #{Bebox::RESERVED_WORDS.join(', ')}
15
+ \n\nNo changes were made." unless Bebox::Profile.valid_name?(profile_name)
16
+ # Clean the profile_path to make it a valid path
17
+ profile_base_path = Bebox::Profile.cleanpath(profile_base_path)
18
+ unless profile_base_path.empty?
19
+ # Check if the path name is valid
20
+ return error "Each part of the path can only contain:\n
21
+ \n* Lowercase letters
22
+ \n* Numbers
23
+ \n* Underscores
24
+ \n* Must begin with an Lowercase letter
25
+ \n* Can not be any of: #{Bebox::RESERVED_WORDS.join(', ')}
26
+ \n\nNo changes were made." unless Bebox::Profile.valid_pathname?(profile_base_path)
27
+ end
28
+ # Check if the profile exist
29
+ profile_path = profile_complete_path(profile_base_path, profile_name)
30
+ return error("The profile '#{profile_path}' already exist. No changes were made.") if profile_exists?(project_root, profile_path)
31
+ # Profile creation
32
+ profile = Bebox::Profile.new(profile_name, project_root, profile_base_path)
33
+ profile.create
34
+ ok "Profile '#{profile_path}' created!."
35
+ end
36
+
37
+ # Removes an existing profile
38
+ def remove_profile(project_root)
39
+ # Choose a profile from the availables
40
+ profiles = Bebox::Profile.list(project_root)
41
+ # Get a profile if exist
42
+ if profiles.count > 0
43
+ profile = choose_profile(profiles, 'Choose the profile to remove:')
44
+ else
45
+ return error "There are no profiles to remove. No changes were made."
46
+ end
47
+ # Ask for deletion confirmation
48
+ return warn('No changes were made.') unless confirm_profile_deletion?
49
+ # Profile deletion
50
+ profile_name = profile.split('/').last
51
+ profile_base_path = profile.split('/')[0...-1].join('/')
52
+ profile = Bebox::Profile.new(profile_name, project_root, profile_base_path)
53
+ profile.remove
54
+ ok 'Profile removed!.'
55
+ end
56
+
57
+ # Lists existing profiles
58
+ def list_profiles(project_root)
59
+ Profile.list(project_root)
60
+ end
61
+
62
+ # Create the complete profile path with name
63
+ def profile_complete_path(profile_base_path, profile_name)
64
+ File.join("#{profile_base_path}", "#{profile_name}")
65
+ end
66
+
67
+ # Check if there's an existing profile in the project
68
+ def profile_exists?(project_root, profile_path)
69
+ Dir.exists?( File.join("#{project_root}/puppet/profiles", "#{profile_path}") )
70
+ end
71
+
72
+ # Ask for confirmation of profile deletion
73
+ def confirm_profile_deletion?
74
+ quest 'Are you sure that you want to delete the profile?'
75
+ response = ask(highline_quest('(y/n)')) do |q|
76
+ q.default = "n"
77
+ end
78
+ return response == 'y' ? true : false
79
+ end
80
+
81
+ # Asks to choose a profile
82
+ def choose_profile(profiles, question)
83
+ choose do |menu|
84
+ menu.header = title(question)
85
+ profiles.each do |box|
86
+ menu.choice(box)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end