r10k 1.4.2 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. data/.travis.yml +2 -0
  2. data/CHANGELOG.mkd +192 -0
  3. data/CONTRIBUTING.mkd +3 -3
  4. data/Gemfile +4 -0
  5. data/README.mkd +13 -6
  6. data/doc/dynamic-environments/configuration.mkd +77 -8
  7. data/doc/dynamic-environments/git-environments.mkd +12 -2
  8. data/doc/dynamic-environments/quickstart.mkd +6 -0
  9. data/doc/faq.mkd +6 -6
  10. data/doc/git/cloning-and-mirroring.mkd +60 -0
  11. data/doc/git/providers.mkd +68 -0
  12. data/integration/Gemfile +3 -0
  13. data/integration/README.mkd +29 -0
  14. data/integration/configs/README.mkd +7 -0
  15. data/integration/configs/pe/centos-6-64mda +25 -0
  16. data/integration/configs/pe/centos-7-64mda +25 -0
  17. data/integration/configs/pe/debian-6-64mda +25 -0
  18. data/integration/configs/pe/debian-7-64mda +25 -0
  19. data/integration/configs/pe/redhat-6-64mda +25 -0
  20. data/integration/configs/pe/redhat-7-64mda +25 -0
  21. data/integration/configs/pe/sles-11-64mda +25 -0
  22. data/integration/configs/pe/ubuntu-1004-64mda +25 -0
  23. data/integration/configs/pe/ubuntu-1204-64mda +25 -0
  24. data/integration/configs/pe/ubuntu-1404-64mda +25 -0
  25. data/integration/files/README.mkd +4 -0
  26. data/integration/files/hiera.yaml +8 -0
  27. data/integration/files/modules/helloworld/manifests/init.pp +3 -0
  28. data/integration/files/modules/hieratest/manifests/init.pp +3 -0
  29. data/integration/files/modules/unicode/files/pretend_unicode +1 -0
  30. data/integration/files/modules/unicode/manifests/init.pp +6 -0
  31. data/integration/files/pre-suite/prod_env.config +3 -0
  32. data/integration/files/r10k_conf.yaml.erb +9 -0
  33. data/integration/lib/README.mkd +4 -0
  34. data/integration/lib/git_utils.rb +205 -0
  35. data/integration/lib/master_manipulator.rb +205 -0
  36. data/integration/lib/r10k_utils.rb +166 -0
  37. data/integration/manifests/README.mkd +4 -0
  38. data/integration/pre-suite/00_pe_install.rb +4 -0
  39. data/integration/pre-suite/01_git_config.rb +59 -0
  40. data/integration/pre-suite/02_pe_r10k.rb +60 -0
  41. data/integration/pre-suite/03_test_utils.rb +17 -0
  42. data/integration/pre-suite/README.mkd +5 -0
  43. data/integration/test_run_scripts/README.mkd +5 -0
  44. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +20 -0
  45. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +20 -0
  46. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +20 -0
  47. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +20 -0
  48. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +20 -0
  49. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +20 -0
  50. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +20 -0
  51. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +20 -0
  52. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +20 -0
  53. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +20 -0
  54. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +20 -0
  55. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +20 -0
  56. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +20 -0
  57. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +20 -0
  58. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +20 -0
  59. data/integration/tests/README.mkd +4 -0
  60. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +46 -0
  61. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +27 -0
  62. data/integration/tests/command_line/deploy_env_without_mod_update.rb +75 -0
  63. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +76 -0
  64. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +22 -0
  65. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +22 -0
  66. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +24 -0
  67. data/integration/tests/git_source/git_source_git.rb +123 -0
  68. data/integration/tests/git_source/git_source_ssh.rb +84 -0
  69. data/integration/tests/git_source/git_source_submodule.rb +69 -0
  70. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +37 -0
  71. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +45 -0
  72. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +72 -0
  73. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +34 -0
  74. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
  75. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +110 -0
  76. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +113 -0
  77. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +93 -0
  78. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +132 -0
  79. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +160 -0
  80. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +45 -0
  81. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +43 -0
  82. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +40 -0
  83. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +42 -0
  84. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +44 -0
  85. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +63 -0
  86. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +73 -0
  87. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +45 -0
  88. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +51 -0
  89. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +33 -0
  90. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +35 -0
  91. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +44 -0
  92. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +57 -0
  93. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +44 -0
  94. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +73 -0
  95. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +103 -0
  96. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +80 -0
  97. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +48 -0
  98. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +73 -0
  99. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +81 -0
  100. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +67 -0
  101. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +93 -0
  102. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +92 -0
  103. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +116 -0
  104. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +59 -0
  105. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +165 -0
  106. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +162 -0
  107. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +110 -0
  108. data/lib/r10k/action/cri_runner.rb +10 -13
  109. data/lib/r10k/cli.rb +3 -8
  110. data/lib/r10k/cli/version.rb +10 -1
  111. data/lib/r10k/deployment/config.rb +26 -6
  112. data/lib/r10k/deployment/config/loader.rb +38 -29
  113. data/lib/r10k/deployment/source.rb +2 -4
  114. data/lib/r10k/environment/git.rb +10 -19
  115. data/lib/r10k/environment/name.rb +86 -0
  116. data/lib/r10k/errors.rb +8 -5
  117. data/lib/r10k/feature.rb +35 -0
  118. data/lib/r10k/feature/collection.rb +23 -0
  119. data/lib/r10k/features.rb +18 -0
  120. data/lib/r10k/git.rb +106 -12
  121. data/lib/r10k/git/alternates.rb +2 -2
  122. data/lib/r10k/git/cache.rb +43 -26
  123. data/lib/r10k/git/errors.rb +12 -6
  124. data/lib/r10k/git/head.rb +3 -0
  125. data/lib/r10k/git/ref.rb +3 -0
  126. data/lib/r10k/git/remote_head.rb +6 -0
  127. data/lib/r10k/git/repository.rb +6 -0
  128. data/lib/r10k/git/rugged.rb +17 -0
  129. data/lib/r10k/git/rugged/bare_repository.rb +86 -0
  130. data/lib/r10k/git/rugged/base_repository.rb +90 -0
  131. data/lib/r10k/git/rugged/cache.rb +11 -0
  132. data/lib/r10k/git/rugged/thin_repository.rb +72 -0
  133. data/lib/r10k/git/rugged/working_repository.rb +99 -0
  134. data/lib/r10k/git/shellgit.rb +9 -0
  135. data/lib/r10k/git/shellgit/bare_repository.rb +29 -0
  136. data/lib/r10k/git/shellgit/base_repository.rb +102 -0
  137. data/lib/r10k/git/shellgit/cache.rb +11 -0
  138. data/lib/r10k/git/shellgit/thin_repository.rb +56 -0
  139. data/lib/r10k/git/shellgit/working_repository.rb +73 -0
  140. data/lib/r10k/git/stateful_repository.rb +80 -0
  141. data/lib/r10k/git/tag.rb +3 -0
  142. data/lib/r10k/git/working_dir.rb +15 -2
  143. data/lib/r10k/logging.rb +73 -36
  144. data/lib/r10k/logging/terminaloutputter.rb +36 -0
  145. data/lib/r10k/module/forge.rb +10 -9
  146. data/lib/r10k/module/git.rb +14 -44
  147. data/lib/r10k/module/metadata_file.rb +31 -0
  148. data/lib/r10k/module/svn.rb +0 -1
  149. data/lib/r10k/module_repository/forge.rb +20 -7
  150. data/lib/r10k/puppetfile.rb +1 -1
  151. data/lib/r10k/settings/container.rb +6 -0
  152. data/lib/r10k/settings/mixin.rb +9 -0
  153. data/lib/r10k/source.rb +2 -3
  154. data/lib/r10k/source/base.rb +5 -5
  155. data/lib/r10k/source/git.rb +11 -86
  156. data/lib/r10k/source/svn.rb +8 -52
  157. data/lib/r10k/util/basedir.rb +4 -4
  158. data/lib/r10k/util/commands.rb +31 -0
  159. data/lib/r10k/util/exec_env.rb +36 -0
  160. data/lib/r10k/util/platform.rb +4 -0
  161. data/lib/r10k/util/purgeable.rb +2 -2
  162. data/lib/r10k/util/subprocess.rb +3 -7
  163. data/lib/r10k/util/subprocess/runner.rb +3 -28
  164. data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
  165. data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
  166. data/lib/r10k/util/subprocess/{windows/runner.rb → runner/windows.rb} +2 -11
  167. data/lib/r10k/util/symbolize_keys.rb +31 -0
  168. data/lib/r10k/version.rb +1 -1
  169. data/lib/shared/puppet/module_tool/metadata.rb +197 -0
  170. data/r10k.gemspec +7 -5
  171. data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
  172. data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
  173. data/spec/fixtures/unit/util/subprocess/posix/runner/no-execute.sh +3 -0
  174. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_all_versions_of_a_given_module.yml +171 -26
  175. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_the_latest_version_of_a_given_module.yml +171 -26
  176. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/ignores_deleted_releases.yml +190 -0
  177. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/it_handles_errors_from_forgeapi_puppetlabs_com/raises_an_error_for_a_non-existant_module.yml +34 -0
  178. data/spec/fixtures/vcr/cassettes/R10K_Module_Forge/and_the_expected_version_is_latest/sets_the_expected_version_based_on_the_latest_forge_version.yml +87 -26
  179. data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
  180. data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
  181. data/spec/integration/git/rugged/working_repository_spec.rb +13 -0
  182. data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
  183. data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
  184. data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
  185. data/spec/integration/git/stateful_repository_spec.rb +104 -0
  186. data/spec/matchers/match_realpath.rb +18 -0
  187. data/spec/shared-contexts/git-fixtures.rb +55 -0
  188. data/spec/shared-examples/git-repository.rb +38 -0
  189. data/spec/shared-examples/git/bare_repository.rb +70 -0
  190. data/spec/shared-examples/git/thin_repository.rb +26 -0
  191. data/spec/shared-examples/git/working_repository.rb +115 -0
  192. data/spec/shared-examples/subprocess-runner.rb +83 -0
  193. data/spec/spec_helper.rb +13 -9
  194. data/spec/unit/action/cri_runner_spec.rb +0 -6
  195. data/spec/unit/action/puppetfile/{cri_action_spec.rb → cri_runner_spec.rb} +0 -0
  196. data/spec/unit/deployment/config/loader_spec.rb +48 -0
  197. data/spec/unit/deployment/config_spec.rb +49 -0
  198. data/spec/unit/environment/git_spec.rb +5 -39
  199. data/spec/unit/environment/name_spec.rb +135 -0
  200. data/spec/unit/feature_spec.rb +50 -0
  201. data/spec/unit/git/alternates_spec.rb +1 -1
  202. data/spec/unit/git/cache_spec.rb +32 -19
  203. data/spec/unit/git/commit_spec.rb +1 -0
  204. data/spec/unit/git/head_spec.rb +1 -6
  205. data/spec/unit/git/ref_spec.rb +0 -23
  206. data/spec/unit/git/rugged/cache_spec.rb +26 -0
  207. data/spec/unit/git/shellgit/cache_spec.rb +27 -0
  208. data/spec/unit/git/stateful_repository_spec.rb +43 -0
  209. data/spec/unit/git/tag_spec.rb +1 -0
  210. data/spec/unit/git/working_dir_spec.rb +1 -0
  211. data/spec/unit/git_spec.rb +74 -0
  212. data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
  213. data/spec/unit/logging_spec.rb +68 -0
  214. data/spec/unit/module/forge_spec.rb +7 -38
  215. data/spec/unit/module/git_spec.rb +7 -38
  216. data/spec/unit/module/metadata_file_spec.rb +69 -0
  217. data/spec/unit/module/svn_spec.rb +0 -4
  218. data/spec/unit/module_repository/forge_spec.rb +22 -1
  219. data/spec/unit/puppet/module_tool/metadata_spec.rb +301 -0
  220. data/spec/unit/settings/container_spec.rb +17 -0
  221. data/spec/unit/source/git_spec.rb +0 -123
  222. data/spec/unit/source/svn_spec.rb +66 -0
  223. data/spec/unit/util/commands_spec.rb +61 -0
  224. data/spec/unit/util/exec_env_spec.rb +56 -0
  225. data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
  226. data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
  227. data/spec/unit/util/subprocess_spec.rb +3 -2
  228. data/spec/unit/util/symbolize_keys_spec.rb +51 -0
  229. metadata +226 -45
  230. data/lib/r10k/execution.rb +0 -47
  231. data/lib/r10k/module/metadata.rb +0 -47
  232. data/lib/r10k/util/core_ext/hash_ext.rb +0 -19
  233. data/lib/r10k/util/subprocess/io.rb +0 -7
  234. data/lib/r10k/util/subprocess/posix.rb +0 -4
  235. data/lib/r10k/util/subprocess/posix/io.rb +0 -7
  236. data/lib/r10k/util/subprocess/posix/runner.rb +0 -140
  237. data/lib/r10k/util/subprocess/windows.rb +0 -4
  238. data/lib/r10k/util/subprocess/windows/io.rb +0 -6
  239. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +0 -42
  240. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +0 -42
  241. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +0 -42
  242. data/spec/unit/deployment/source_spec.rb +0 -24
  243. data/spec/unit/module/metadata_spec.rb +0 -68
  244. data/spec/unit/util/core_ext/hash_ext_spec.rb +0 -63
@@ -0,0 +1,4 @@
1
+ Files
2
+ ===========================
3
+
4
+ This folder contains files used for testing the r10k project. The files are organized by test suite.
@@ -0,0 +1,8 @@
1
+ ---
2
+ :backends:
3
+ - yaml
4
+ :hierarchy:
5
+ - "%{environment}"
6
+
7
+ :yaml:
8
+ :datadir: "/etc/puppetlabs/puppet/environments/%{environment}/hiera"
@@ -0,0 +1,3 @@
1
+ class helloworld {
2
+ notify { "Hello world!": message => "I am in the ${environment} environment"}
3
+ }
@@ -0,0 +1,3 @@
1
+ class hieratest ($hiera_message = "default text") {
2
+ notify { "Hiera test!": message => $hiera_message}
3
+ }
@@ -0,0 +1 @@
1
+ Ha ha ha! I am in Korean!
@@ -0,0 +1,6 @@
1
+ class unicode {
2
+ file { '/tmp/unicode.file':
3
+ ensure => file,
4
+ source => "puppet:///modules/unicode/굢챣샃뻧븣럩윕컾뾐깩"
5
+ }
6
+ }
@@ -0,0 +1,3 @@
1
+ # Puppet Enterprise requires $basemodulepath
2
+ modulepath = site:dist:modules:$basemodulepath
3
+ manifest = manifests/site.pp
@@ -0,0 +1,9 @@
1
+ cachedir: '/var/cache/r10k'
2
+ git:
3
+ provider: '<%= git_provider %>'
4
+ sources:
5
+ <% for source in sources %>
6
+ <%= source.repo_name %>:
7
+ basedir: "<%= env_path %>"
8
+ remote: "<%= source.control_remote %>"
9
+ <% end %>
@@ -0,0 +1,4 @@
1
+ Lib
2
+ ===========================
3
+
4
+ This folder contains Ruby files that extends Beaker.
@@ -0,0 +1,205 @@
1
+ # Execute a git command on a host.
2
+ #
3
+ # ==== Attributes
4
+ #
5
+ # * +host+ - One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.
6
+ # * +git_sub_command+ - The git sub-command to execute including arguments. (The 'git' command is assumed.)
7
+ # * +git_repo_path+ - The path to the git repository on the target host.
8
+ # * +opts+ - Options to alter execution.
9
+ #
10
+ # ==== Returns
11
+ #
12
+ # +nil+
13
+ #
14
+ # ==== Examples
15
+ #
16
+ # git_on(master, 'add file.txt', '~/git_repo')
17
+ def git_on(host, git_sub_command, git_repo_path, opts = {})
18
+ git_command = "git --git-dir=#{git_repo_path}/.git --work-tree=#{git_repo_path} #{git_sub_command}"
19
+
20
+ on(host, git_command, opts)
21
+ end
22
+
23
+ # Add all uncommitted files located in a repository.
24
+ #
25
+ # ==== Attributes
26
+ #
27
+ # * +host+ - One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.
28
+ # * +git_repo_path+ - The path to the git repository on the target host.
29
+ #
30
+ # ==== Returns
31
+ #
32
+ # +nil+
33
+ #
34
+ # ==== Examples
35
+ #
36
+ # git_add_everything(master, '~/git_repo')
37
+ def git_add_everything(host, git_repo_path)
38
+ git_on(host, "add #{git_repo_path}/*", git_repo_path)
39
+ end
40
+
41
+ # Push branch to origin remote.
42
+ #
43
+ # ==== Attributes
44
+ #
45
+ # * +host+ - One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.
46
+ # * +branch+ - The branch to push.
47
+ # * +git_repo_path+ - The path to the git repository on the target host.
48
+ #
49
+ # ==== Returns
50
+ #
51
+ # +nil+
52
+ #
53
+ # ==== Examples
54
+ #
55
+ # git_push(master, 'production', '~/git_repo')
56
+ def git_push(host, branch, git_repo_path)
57
+ git_on(host, "push origin #{branch}", git_repo_path)
58
+ end
59
+
60
+ # Commit changes and push branch to origin remote.
61
+ #
62
+ # ==== Attributes
63
+ #
64
+ # * +host+ - One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.
65
+ # * +branch+ - The branch to push.
66
+ # * +message+ - A single-line commit message. (Don't quote message!)
67
+ # * +git_repo_path+ - The path to the git repository on the target host.
68
+ #
69
+ # ==== Returns
70
+ #
71
+ # +nil+
72
+ #
73
+ # ==== Examples
74
+ #
75
+ # git_commit_push(master, 'production', 'Awesome stuff!', '~/git_repo')
76
+ def git_commit_push(host, branch, message, git_repo_path)
77
+ git_on(host, "commit -m \"#{message}\"", git_repo_path)
78
+ git_push(host, branch, git_repo_path)
79
+ end
80
+
81
+ # Add all uncommitted files located in a repository, commit changes and push branch to origin remote.
82
+ #
83
+ # ==== Attributes
84
+ #
85
+ # * +host+ - One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.
86
+ # * +branch+ - The branch to push.
87
+ # * +message+ - A single-line commit message. (Don't quote message!)
88
+ # * +git_repo_path+ - The path to the git repository on the target host.
89
+ #
90
+ # ==== Returns
91
+ #
92
+ # +nil+
93
+ #
94
+ # ==== Examples
95
+ #
96
+ # git_add_commit_push(master, 'production', 'Awesome stuff!', '~/git_repo')
97
+ def git_add_commit_push(host, branch, message, git_repo_path)
98
+ git_add_everything(host, git_repo_path)
99
+ git_commit_push(host, branch, message, git_repo_path)
100
+ end
101
+
102
+ # Get the last commit SHA.
103
+ #
104
+ # ==== Attributes
105
+ #
106
+ # * +host+ - One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.
107
+ # * +git_repo_path+ - The path to the git repository on the target host.
108
+ #
109
+ # ==== Returns
110
+ #
111
+ # +string+ - The SHA of the last commit.
112
+ #
113
+ # ==== Examples
114
+ #
115
+ # last_commit = git_last_commit(master, '~/git_repo')
116
+ def git_last_commit(host, git_repo_path)
117
+ sha_regex = /commit (\w{40})/
118
+
119
+ return sha_regex.match(git_on(host, 'log', git_repo_path).stdout)[1]
120
+ end
121
+
122
+ # Hard reset the git repository to a specific commit.
123
+ #
124
+ # ==== Attributes
125
+ #
126
+ # * +host+ - One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.
127
+ # * +commit_sha+ - The reset HEAD to this commit SHA.
128
+ # * +git_repo_path+ - The path to the git repository on the target host.
129
+ #
130
+ # ==== Returns
131
+ #
132
+ # +nil+
133
+ #
134
+ # ==== Examples
135
+ #
136
+ # git_reset_hard(master, 'ff81c01c5', '~/git_repo')
137
+ def git_reset_hard(host, commit_sha, git_repo_path)
138
+ git_on(host, "reset --hard #{commit_sha}", git_repo_path)
139
+ end
140
+
141
+ # Create a bare Git repository.
142
+ #
143
+ # ==== Attributes
144
+ #
145
+ # * +host+ - The Puppet host on which to create a bare git repo.
146
+ # * +git_repo_parent_path+ - The parent path that contains the desired Git repository.
147
+ # * +git_repo_name+ - The name of the repository.
148
+ #
149
+ # ==== Returns
150
+ #
151
+ # +string+ - The path to the newly created Git repository.
152
+ #
153
+ # ==== Examples
154
+ #
155
+ # git_init_bare_repo(master, '/git/repos', 'environments')
156
+ def git_init_bare_repo(host, git_repo_parent_path, git_repo_name)
157
+ #Init
158
+ git_repo_path = File.join(git_repo_parent_path, "#{git_repo_name}.git")
159
+
160
+ #Initialize bare Git repository
161
+ on(host, "mkdir -p #{git_repo_path}")
162
+ on(host, "git init --bare #{git_repo_path}")
163
+
164
+ return git_repo_path
165
+ end
166
+
167
+ # Clone a Git repository.
168
+ #
169
+ # ==== Attributes
170
+ #
171
+ # * +host+ - The Puppet host on which to create a bare git repo.
172
+ # * +git_clone_path+ - The destination path for the git clone.
173
+ # * +git_source+ - The origin from which to clone.
174
+ #
175
+ # ==== Returns
176
+ #
177
+ # +nil+
178
+ #
179
+ # ==== Examples
180
+ #
181
+ # git_clone_repo(master, '~/repos/r10k', '/git/repos/environments.git')
182
+ def git_clone_repo(host, git_clone_path, git_source)
183
+ on(host, "git clone #{git_source} #{git_clone_path}")
184
+ end
185
+
186
+ # Create a bare Git repository and then clone the repository.
187
+ #
188
+ # ==== Attributes
189
+ #
190
+ # * +host+ - The Puppet host on which to create a bare git repo.
191
+ # * +git_repo_parent_path+ - The parent path that contains the desired Git repository.
192
+ # * +git_repo_name+ - The name of the repository.
193
+ # * +git_clone_path+ - The destination path for the git clone.
194
+ #
195
+ # ==== Returns
196
+ #
197
+ # +string+ - The path to the newly created Git repository.
198
+ #
199
+ # ==== Examples
200
+ #
201
+ # git_init_bare_repo_and_clone(master, '/git/repos', 'environments', '~/repos/r10k')
202
+ def git_init_bare_repo_and_clone(host, git_repo_parent_path, git_repo_name, git_clone_path)
203
+ origin_git_repo_path = git_init_bare_repo(host, git_repo_parent_path, git_repo_name)
204
+ git_clone_repo(host, git_clone_path, origin_git_repo_path)
205
+ end
@@ -0,0 +1,205 @@
1
+ # Create a "site.pp" file with file bucket enabled. Also, allow
2
+ # the creation of a custom node definition or use the 'default'
3
+ # node definition.
4
+ #
5
+ # ==== Attributes
6
+ #
7
+ # * +master_certname+ - Certificate name of Puppet master.
8
+ # * +manifest+ - A Puppet manifest to inject into the node definition.
9
+ # * +node_def_name+ - A node definition pattern or name.
10
+ #
11
+ # ==== Returns
12
+ #
13
+ # +string+ - A combined manifest with node definition containing input manifest
14
+ #
15
+ # ==== Examples
16
+ #
17
+ # site_pp = create_site_pp("puppetmaster", '', node_def_name='agent')
18
+ def create_site_pp(master_certname, manifest='', node_def_name='default')
19
+ default_def = <<-MANIFEST
20
+ node default {
21
+ }
22
+ MANIFEST
23
+
24
+ node_def = <<-MANIFEST
25
+ node #{node_def_name} {
26
+
27
+ #{manifest}
28
+ }
29
+ MANIFEST
30
+
31
+ if node_def_name != 'default'
32
+ node_def = "#{default_def}\n#{node_def}"
33
+ end
34
+
35
+ site_pp = <<-MANIFEST
36
+ filebucket { 'main':
37
+ server => '#{master_certname}',
38
+ path => false,
39
+ }
40
+
41
+ File { backup => 'main' }
42
+
43
+ #{node_def}
44
+ MANIFEST
45
+
46
+ return site_pp
47
+ end
48
+
49
+ # Read a Puppet manifest file and inject the content into a
50
+ # "default" node definition. (Used mostly to overide site.pp)
51
+ #
52
+ # ==== Attributes
53
+ #
54
+ # * +manifest_path+ - The file path to target manifest.
55
+ # * +master_certname+ - Certificate name of Puppet master.
56
+ #
57
+ # ==== Returns
58
+ #
59
+ # +string+ - A combined manifest with node definition containg input manifest
60
+ #
61
+ # ==== Examples
62
+ #
63
+ # site_pp = create_node_manifest("/tmp/test.pp", "master")
64
+ def create_node_manifest(manifest_path, master_certname, node_def_name='default')
65
+ manifest = File.read(manifest_path)
66
+
67
+ site_pp = <<-MANIFEST
68
+ filebucket { 'main':
69
+ server => '#{master_certname}',
70
+ path => false,
71
+ }
72
+
73
+ File { backup => 'main' }
74
+
75
+ node default {
76
+
77
+ #{manifest}
78
+ }
79
+ MANIFEST
80
+
81
+ return site_pp
82
+ end
83
+
84
+ # Set mode, owner and group on a remote path.
85
+ #
86
+ # ==== Attributes
87
+ #
88
+ # * +host+ - The remote host containing the target path.
89
+ # * +path+ - The path to set mode, user and group upon.
90
+ # * +mode+ - The desired mode to set on the path in as a string.
91
+ # * +owner+ - The owner to set on the path. (Puppet user if not specified.)
92
+ # * +group+ - The group to set on the path. (Puppet group if not specified.)
93
+ #
94
+ # ==== Returns
95
+ #
96
+ # nil
97
+ #
98
+ # ==== Examples
99
+ #
100
+ # set_perms_on_remote(master, "/tmp/test/site.pp", "777")
101
+ def set_perms_on_remote(host, path, mode, owner=nil, group=nil)
102
+ if (owner.nil?)
103
+ owner = on(host, puppet('config', 'print', 'user')).stdout.rstrip
104
+ end
105
+
106
+ if (group.nil?)
107
+ group = on(host, puppet('config', 'print', 'group')).stdout.rstrip
108
+ end
109
+
110
+ on(host, "chmod -R #{mode} #{path}")
111
+ on(host, "chown -R #{owner}:#{group} #{path}")
112
+ end
113
+
114
+ # Inject temporary "site.pp" onto target host. This will also create
115
+ # a "modules" folder in the target remote directory.
116
+ #
117
+ # ==== Attributes
118
+ #
119
+ # * +master+ - The target master for injection.
120
+ # * +site_pp_path+ - A path on the remote host into which the site.pp will be injected.
121
+ # * +manifest+ - The manifest content to inject into "site.pp" to the host target path.
122
+ #
123
+ # ==== Returns
124
+ #
125
+ # nil
126
+ #
127
+ # ==== Examples
128
+ #
129
+ # site_pp = inject_site_pp(master, "/tmp/test/site.pp", manifest)
130
+ def inject_site_pp(master, site_pp_path, manifest)
131
+ site_pp_dir = File.dirname(site_pp_path)
132
+ create_remote_file(master, site_pp_path, manifest)
133
+
134
+ set_perms_on_remote(master, site_pp_dir, "777")
135
+ end
136
+
137
+ # Create a temporary directory environment and inject a "site.pp" for the target environment.
138
+ #
139
+ # ==== Attributes
140
+ #
141
+ # * +master+ - The master on which to create a new Puppet environment.
142
+ # * +env_root_path+ - The base path on the master that contains all environments.
143
+ # * +env_seed_name+ - The seed name to use for generating an environment name.
144
+ # * +manifest+ - The manifest content to inject into "site.pp" of the newly created environment.
145
+ #
146
+ # ==== Returns
147
+ #
148
+ # +string+ - The environment name that was generated.
149
+ #
150
+ # ==== Examples
151
+ #
152
+ # temp_env_name = create_temp_dir_env(master, "/tmp/test/site.pp", "stuff", manifest)
153
+ def create_temp_dir_env(master, env_root_path, env_seed_name, manifest)
154
+ env_name = "#{env_seed_name}" + rand(36**16).to_s(36)
155
+ env_path = "#{env_root_path}/#{env_name}"
156
+ env_site_pp_path = "#{env_path}/manifests/site.pp"
157
+
158
+ on(master, "mkdir -p #{env_path}/manifests #{env_path}/modules")
159
+ set_perms_on_remote(master, env_path, "777")
160
+
161
+ inject_site_pp(master, env_site_pp_path, manifest)
162
+
163
+ return env_name
164
+ end
165
+
166
+ # Restart the puppet server and wait for it to come back up
167
+ # ==== Attributes
168
+ # *+host+ - the host that this should operate on
169
+ # *+opts+ - an options hash - not required
170
+ # *+:timeout+ - the amount of time in seconds to wait for success
171
+ # *+:frequency+ - The time to wait between retries
172
+ #
173
+ # Raises a standard error if the wait is uncessfull
174
+ #
175
+ # ==== Example
176
+ # restart_puppet_server(master)
177
+ # restart_puppet_server(master, {:time_out => 200, :frequency => 10})
178
+ def restart_puppet_server(host, opts = {})
179
+
180
+ on(host, "puppet resource service pe-puppetserver ensure=stopped")
181
+ on(host, "puppet resource service pe-puppetserver ensure=running")
182
+ masterHostName = on(host, "hostname").stdout.chomp
183
+ opts[:time_out] ||= 100
184
+ opts[:frequency] ||= 5
185
+ i = 0
186
+
187
+ # -k to ignore HTTPS error that isn't relevant to us
188
+ curl_call = "-I -k https://#{masterHostName}:8140/production/certificate_statuses/all"
189
+
190
+ while i < opts[:time_out] do
191
+ sleep opts[:frequency]
192
+ i += 1
193
+ exit_code = curl_on(host, curl_call, :acceptable_exit_codes => [0,1,7]).exit_code
194
+
195
+ # Exit code 7 is "connection refused"
196
+ if exit_code != '7'
197
+ sleep 20
198
+ puts 'Restarting the Puppet Server was successful!'
199
+ return
200
+ end
201
+ end
202
+
203
+ raise StandardError, 'Attempting to restart the puppet server was not successful in the time alloted.'
204
+
205
+ end