openbolt 5.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. checksums.yaml +7 -0
  2. data/Puppetfile +52 -0
  3. data/bolt-modules/boltlib/lib/puppet/datatypes/applyresult.rb +60 -0
  4. data/bolt-modules/boltlib/lib/puppet/datatypes/containerresult.rb +51 -0
  5. data/bolt-modules/boltlib/lib/puppet/datatypes/future.rb +25 -0
  6. data/bolt-modules/boltlib/lib/puppet/datatypes/resourceinstance.rb +71 -0
  7. data/bolt-modules/boltlib/lib/puppet/datatypes/result.rb +55 -0
  8. data/bolt-modules/boltlib/lib/puppet/datatypes/resultset.rb +65 -0
  9. data/bolt-modules/boltlib/lib/puppet/datatypes/target.rb +93 -0
  10. data/bolt-modules/boltlib/lib/puppet/functions/add_facts.rb +33 -0
  11. data/bolt-modules/boltlib/lib/puppet/functions/add_to_group.rb +38 -0
  12. data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +208 -0
  13. data/bolt-modules/boltlib/lib/puppet/functions/background.rb +62 -0
  14. data/bolt-modules/boltlib/lib/puppet/functions/catch_errors.rb +57 -0
  15. data/bolt-modules/boltlib/lib/puppet/functions/download_file.rb +130 -0
  16. data/bolt-modules/boltlib/lib/puppet/functions/facts.rb +31 -0
  17. data/bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb +52 -0
  18. data/bolt-modules/boltlib/lib/puppet/functions/get_resources.rb +87 -0
  19. data/bolt-modules/boltlib/lib/puppet/functions/get_target.rb +34 -0
  20. data/bolt-modules/boltlib/lib/puppet/functions/get_targets.rb +35 -0
  21. data/bolt-modules/boltlib/lib/puppet/functions/parallelize.rb +74 -0
  22. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_command.rb +97 -0
  23. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb +47 -0
  24. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +52 -0
  25. data/bolt-modules/boltlib/lib/puppet/functions/remove_from_group.rb +40 -0
  26. data/bolt-modules/boltlib/lib/puppet/functions/resolve_references.rb +42 -0
  27. data/bolt-modules/boltlib/lib/puppet/functions/resource.rb +53 -0
  28. data/bolt-modules/boltlib/lib/puppet/functions/run_command.rb +106 -0
  29. data/bolt-modules/boltlib/lib/puppet/functions/run_container.rb +162 -0
  30. data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +291 -0
  31. data/bolt-modules/boltlib/lib/puppet/functions/run_script.rb +145 -0
  32. data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +164 -0
  33. data/bolt-modules/boltlib/lib/puppet/functions/run_task_with.rb +211 -0
  34. data/bolt-modules/boltlib/lib/puppet/functions/set_config.rb +48 -0
  35. data/bolt-modules/boltlib/lib/puppet/functions/set_feature.rb +43 -0
  36. data/bolt-modules/boltlib/lib/puppet/functions/set_resources.rb +145 -0
  37. data/bolt-modules/boltlib/lib/puppet/functions/set_var.rb +38 -0
  38. data/bolt-modules/boltlib/lib/puppet/functions/upload_file.rb +101 -0
  39. data/bolt-modules/boltlib/lib/puppet/functions/vars.rb +29 -0
  40. data/bolt-modules/boltlib/lib/puppet/functions/wait.rb +131 -0
  41. data/bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb +59 -0
  42. data/bolt-modules/boltlib/lib/puppet/functions/without_default_logging.rb +39 -0
  43. data/bolt-modules/boltlib/lib/puppet/functions/write_file.rb +50 -0
  44. data/bolt-modules/boltlib/types/planresult.pp +18 -0
  45. data/bolt-modules/boltlib/types/targetspec.pp +7 -0
  46. data/bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb +42 -0
  47. data/bolt-modules/ctrl/lib/puppet/functions/ctrl/sleep.rb +20 -0
  48. data/bolt-modules/dir/lib/puppet/functions/dir/children.rb +35 -0
  49. data/bolt-modules/file/lib/puppet/functions/file/delete.rb +21 -0
  50. data/bolt-modules/file/lib/puppet/functions/file/exists.rb +28 -0
  51. data/bolt-modules/file/lib/puppet/functions/file/join.rb +20 -0
  52. data/bolt-modules/file/lib/puppet/functions/file/read.rb +33 -0
  53. data/bolt-modules/file/lib/puppet/functions/file/readable.rb +28 -0
  54. data/bolt-modules/file/lib/puppet/functions/file/write.rb +24 -0
  55. data/bolt-modules/log/lib/puppet/functions/log/debug.rb +39 -0
  56. data/bolt-modules/log/lib/puppet/functions/log/error.rb +40 -0
  57. data/bolt-modules/log/lib/puppet/functions/log/fatal.rb +40 -0
  58. data/bolt-modules/log/lib/puppet/functions/log/info.rb +39 -0
  59. data/bolt-modules/log/lib/puppet/functions/log/trace.rb +39 -0
  60. data/bolt-modules/log/lib/puppet/functions/log/warn.rb +41 -0
  61. data/bolt-modules/out/lib/puppet/functions/out/message.rb +36 -0
  62. data/bolt-modules/out/lib/puppet/functions/out/verbose.rb +35 -0
  63. data/bolt-modules/prompt/lib/puppet/functions/prompt/menu.rb +103 -0
  64. data/bolt-modules/prompt/lib/puppet/functions/prompt.rb +65 -0
  65. data/bolt-modules/system/lib/puppet/functions/system/env.rb +20 -0
  66. data/exe/bolt +17 -0
  67. data/guides/debugging.yaml +27 -0
  68. data/guides/inventory.yaml +23 -0
  69. data/guides/links.yaml +12 -0
  70. data/guides/logging.yaml +17 -0
  71. data/guides/module.yaml +18 -0
  72. data/guides/modulepath.yaml +24 -0
  73. data/guides/project.yaml +21 -0
  74. data/guides/targets.yaml +28 -0
  75. data/guides/transports.yaml +22 -0
  76. data/lib/bolt/analytics.rb +233 -0
  77. data/lib/bolt/application.rb +806 -0
  78. data/lib/bolt/applicator.rb +368 -0
  79. data/lib/bolt/apply_inventory.rb +93 -0
  80. data/lib/bolt/apply_result.rb +154 -0
  81. data/lib/bolt/apply_target.rb +90 -0
  82. data/lib/bolt/bolt_option_parser.rb +1226 -0
  83. data/lib/bolt/catalog/logging.rb +15 -0
  84. data/lib/bolt/catalog.rb +144 -0
  85. data/lib/bolt/cli.rb +949 -0
  86. data/lib/bolt/config/modulepath.rb +30 -0
  87. data/lib/bolt/config/options.rb +673 -0
  88. data/lib/bolt/config/transport/base.rb +133 -0
  89. data/lib/bolt/config/transport/docker.rb +34 -0
  90. data/lib/bolt/config/transport/jail.rb +33 -0
  91. data/lib/bolt/config/transport/local.rb +39 -0
  92. data/lib/bolt/config/transport/lxd.rb +34 -0
  93. data/lib/bolt/config/transport/options.rb +431 -0
  94. data/lib/bolt/config/transport/orch.rb +41 -0
  95. data/lib/bolt/config/transport/podman.rb +33 -0
  96. data/lib/bolt/config/transport/remote.rb +24 -0
  97. data/lib/bolt/config/transport/ssh.rb +138 -0
  98. data/lib/bolt/config/transport/winrm.rb +63 -0
  99. data/lib/bolt/config.rb +515 -0
  100. data/lib/bolt/container_result.rb +105 -0
  101. data/lib/bolt/error.rb +194 -0
  102. data/lib/bolt/executor.rb +539 -0
  103. data/lib/bolt/fiber_executor.rb +190 -0
  104. data/lib/bolt/inventory/group.rb +446 -0
  105. data/lib/bolt/inventory/inventory.rb +391 -0
  106. data/lib/bolt/inventory/options.rb +139 -0
  107. data/lib/bolt/inventory/target.rb +293 -0
  108. data/lib/bolt/inventory.rb +120 -0
  109. data/lib/bolt/logger.rb +252 -0
  110. data/lib/bolt/module.rb +54 -0
  111. data/lib/bolt/module_installer/installer.rb +44 -0
  112. data/lib/bolt/module_installer/puppetfile/forge_module.rb +54 -0
  113. data/lib/bolt/module_installer/puppetfile/git_module.rb +37 -0
  114. data/lib/bolt/module_installer/puppetfile/module.rb +26 -0
  115. data/lib/bolt/module_installer/puppetfile.rb +131 -0
  116. data/lib/bolt/module_installer/resolver.rb +129 -0
  117. data/lib/bolt/module_installer/specs/forge_spec.rb +91 -0
  118. data/lib/bolt/module_installer/specs/git_spec.rb +150 -0
  119. data/lib/bolt/module_installer/specs/id/base.rb +116 -0
  120. data/lib/bolt/module_installer/specs/id/gitclone.rb +120 -0
  121. data/lib/bolt/module_installer/specs/id/github.rb +90 -0
  122. data/lib/bolt/module_installer/specs/id/gitlab.rb +92 -0
  123. data/lib/bolt/module_installer/specs.rb +95 -0
  124. data/lib/bolt/module_installer.rb +208 -0
  125. data/lib/bolt/node/errors.rb +55 -0
  126. data/lib/bolt/node/output.rb +29 -0
  127. data/lib/bolt/outputter/human.rb +958 -0
  128. data/lib/bolt/outputter/json.rb +205 -0
  129. data/lib/bolt/outputter/logger.rb +76 -0
  130. data/lib/bolt/outputter/rainbow.rb +118 -0
  131. data/lib/bolt/outputter.rb +57 -0
  132. data/lib/bolt/pal/issues.rb +19 -0
  133. data/lib/bolt/pal/logging.rb +17 -0
  134. data/lib/bolt/pal/yaml_plan/evaluator.rb +83 -0
  135. data/lib/bolt/pal/yaml_plan/loader.rb +94 -0
  136. data/lib/bolt/pal/yaml_plan/parameter.rb +63 -0
  137. data/lib/bolt/pal/yaml_plan/step/command.rb +45 -0
  138. data/lib/bolt/pal/yaml_plan/step/download.rb +37 -0
  139. data/lib/bolt/pal/yaml_plan/step/eval.rb +42 -0
  140. data/lib/bolt/pal/yaml_plan/step/message.rb +31 -0
  141. data/lib/bolt/pal/yaml_plan/step/plan.rb +42 -0
  142. data/lib/bolt/pal/yaml_plan/step/resources.rb +170 -0
  143. data/lib/bolt/pal/yaml_plan/step/script.rb +62 -0
  144. data/lib/bolt/pal/yaml_plan/step/task.rb +42 -0
  145. data/lib/bolt/pal/yaml_plan/step/upload.rb +37 -0
  146. data/lib/bolt/pal/yaml_plan/step/verbose.rb +31 -0
  147. data/lib/bolt/pal/yaml_plan/step.rb +223 -0
  148. data/lib/bolt/pal/yaml_plan/transpiler.rb +90 -0
  149. data/lib/bolt/pal/yaml_plan.rb +172 -0
  150. data/lib/bolt/pal.rb +847 -0
  151. data/lib/bolt/plan_creator.rb +219 -0
  152. data/lib/bolt/plan_future.rb +86 -0
  153. data/lib/bolt/plan_result.rb +44 -0
  154. data/lib/bolt/plugin/cache.rb +76 -0
  155. data/lib/bolt/plugin/env_var.rb +54 -0
  156. data/lib/bolt/plugin/module.rb +276 -0
  157. data/lib/bolt/plugin/prompt.rb +36 -0
  158. data/lib/bolt/plugin/puppet_connect_data.rb +84 -0
  159. data/lib/bolt/plugin/puppetdb.rb +124 -0
  160. data/lib/bolt/plugin/task.rb +72 -0
  161. data/lib/bolt/plugin.rb +380 -0
  162. data/lib/bolt/project.rb +219 -0
  163. data/lib/bolt/project_manager/config_migrator.rb +113 -0
  164. data/lib/bolt/project_manager/inventory_migrator.rb +67 -0
  165. data/lib/bolt/project_manager/migrator.rb +39 -0
  166. data/lib/bolt/project_manager/module_migrator.rb +203 -0
  167. data/lib/bolt/project_manager.rb +221 -0
  168. data/lib/bolt/puppetdb/client.rb +153 -0
  169. data/lib/bolt/puppetdb/config.rb +176 -0
  170. data/lib/bolt/puppetdb/instance.rb +146 -0
  171. data/lib/bolt/puppetdb.rb +15 -0
  172. data/lib/bolt/r10k_log_proxy.rb +30 -0
  173. data/lib/bolt/rerun.rb +55 -0
  174. data/lib/bolt/resource_instance.rb +133 -0
  175. data/lib/bolt/result.rb +247 -0
  176. data/lib/bolt/result_set.rb +128 -0
  177. data/lib/bolt/shell/bash/tmpdir.rb +62 -0
  178. data/lib/bolt/shell/bash.rb +516 -0
  179. data/lib/bolt/shell/powershell/snippets.rb +181 -0
  180. data/lib/bolt/shell/powershell.rb +365 -0
  181. data/lib/bolt/shell.rb +105 -0
  182. data/lib/bolt/target.rb +174 -0
  183. data/lib/bolt/task/puppet_server.rb +27 -0
  184. data/lib/bolt/task/run.rb +55 -0
  185. data/lib/bolt/task.rb +163 -0
  186. data/lib/bolt/transport/base.rb +252 -0
  187. data/lib/bolt/transport/docker/connection.rb +150 -0
  188. data/lib/bolt/transport/docker.rb +23 -0
  189. data/lib/bolt/transport/jail/connection.rb +81 -0
  190. data/lib/bolt/transport/jail.rb +21 -0
  191. data/lib/bolt/transport/local/connection.rb +106 -0
  192. data/lib/bolt/transport/local.rb +20 -0
  193. data/lib/bolt/transport/lxd/connection.rb +115 -0
  194. data/lib/bolt/transport/lxd.rb +26 -0
  195. data/lib/bolt/transport/orch/connection.rb +111 -0
  196. data/lib/bolt/transport/orch.rb +271 -0
  197. data/lib/bolt/transport/podman/connection.rb +102 -0
  198. data/lib/bolt/transport/podman.rb +19 -0
  199. data/lib/bolt/transport/remote.rb +41 -0
  200. data/lib/bolt/transport/simple.rb +54 -0
  201. data/lib/bolt/transport/ssh/connection.rb +321 -0
  202. data/lib/bolt/transport/ssh/exec_connection.rb +140 -0
  203. data/lib/bolt/transport/ssh.rb +48 -0
  204. data/lib/bolt/transport/winrm/connection.rb +378 -0
  205. data/lib/bolt/transport/winrm.rb +33 -0
  206. data/lib/bolt/util/format.rb +68 -0
  207. data/lib/bolt/util/puppet_log_level.rb +21 -0
  208. data/lib/bolt/util.rb +465 -0
  209. data/lib/bolt/validator.rb +227 -0
  210. data/lib/bolt/version.rb +5 -0
  211. data/lib/bolt.rb +8 -0
  212. data/lib/bolt_server/acl.rb +39 -0
  213. data/lib/bolt_server/base_config.rb +112 -0
  214. data/lib/bolt_server/config.rb +64 -0
  215. data/lib/bolt_server/file_cache.rb +200 -0
  216. data/lib/bolt_server/request_error.rb +11 -0
  217. data/lib/bolt_server/schemas/action-check_node_connections.json +14 -0
  218. data/lib/bolt_server/schemas/action-run_command.json +12 -0
  219. data/lib/bolt_server/schemas/action-run_script.json +47 -0
  220. data/lib/bolt_server/schemas/action-run_task.json +20 -0
  221. data/lib/bolt_server/schemas/action-upload_file.json +47 -0
  222. data/lib/bolt_server/schemas/partials/target-any.json +10 -0
  223. data/lib/bolt_server/schemas/partials/target-ssh.json +88 -0
  224. data/lib/bolt_server/schemas/partials/target-winrm.json +67 -0
  225. data/lib/bolt_server/schemas/partials/task.json +94 -0
  226. data/lib/bolt_server/schemas/transport-ssh.json +25 -0
  227. data/lib/bolt_server/schemas/transport-winrm.json +19 -0
  228. data/lib/bolt_server/transport_app.rb +554 -0
  229. data/lib/bolt_spec/bolt_context.rb +226 -0
  230. data/lib/bolt_spec/plans/action_stubs/command_stub.rb +51 -0
  231. data/lib/bolt_spec/plans/action_stubs/download_stub.rb +66 -0
  232. data/lib/bolt_spec/plans/action_stubs/plan_stub.rb +55 -0
  233. data/lib/bolt_spec/plans/action_stubs/script_stub.rb +59 -0
  234. data/lib/bolt_spec/plans/action_stubs/task_stub.rb +57 -0
  235. data/lib/bolt_spec/plans/action_stubs/upload_stub.rb +65 -0
  236. data/lib/bolt_spec/plans/action_stubs.rb +196 -0
  237. data/lib/bolt_spec/plans/mock_executor.rb +361 -0
  238. data/lib/bolt_spec/plans/publish_stub.rb +49 -0
  239. data/lib/bolt_spec/plans.rb +190 -0
  240. data/lib/bolt_spec/run.rb +246 -0
  241. data/lib/logging_extensions/logging.rb +13 -0
  242. data/libexec/apply_catalog.rb +130 -0
  243. data/libexec/bolt_catalog +68 -0
  244. data/libexec/custom_facts.rb +63 -0
  245. data/libexec/query_resources.rb +75 -0
  246. data/modules/aggregate/lib/puppet/functions/aggregate/count.rb +21 -0
  247. data/modules/aggregate/lib/puppet/functions/aggregate/nodes.rb +22 -0
  248. data/modules/aggregate/lib/puppet/functions/aggregate/targets.rb +21 -0
  249. data/modules/aggregate/plans/count.pp +56 -0
  250. data/modules/aggregate/plans/targets.pp +56 -0
  251. data/modules/canary/lib/puppet/functions/canary/merge.rb +13 -0
  252. data/modules/canary/lib/puppet/functions/canary/random_split.rb +22 -0
  253. data/modules/canary/lib/puppet/functions/canary/skip.rb +25 -0
  254. data/modules/canary/plans/init.pp +100 -0
  255. data/modules/puppet_connect/plans/test_input_data.pp +94 -0
  256. data/modules/puppetdb_fact/plans/init.pp +20 -0
  257. data/resources/bolt_bash_completion.sh +214 -0
  258. metadata +735 -0
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Check if a local file is readable using Puppet's
4
+ # `Puppet::Parser::Files.find_file()` function. This will only check files on the
5
+ # machine you run Bolt on.
6
+ Puppet::Functions.create_function(:'file::readable', Puppet::Functions::InternalFunction) do
7
+ # @param filename Absolute path or Puppet file path.
8
+ # @return Whether the file is readable.
9
+ # @example Check a file on disk
10
+ # file::readable('/tmp/i_dumped_this_here')
11
+ # @example check a file from the modulepath
12
+ # file::readable('example/VERSION')
13
+ dispatch :readable do
14
+ scope_param
15
+ required_param 'String[1]', :filename
16
+ return_type 'Boolean'
17
+ end
18
+
19
+ def readable(scope, filename)
20
+ # Send Analytics Report
21
+ executor = Puppet.lookup(:bolt_executor) {}
22
+ executor&.report_function_call(self.class.name)
23
+
24
+ # Find the file path if it exists, otherwise return nil
25
+ found = Bolt::Util.find_file_from_scope(filename, scope)
26
+ found ? File.readable?(found) : false
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Write a string to a file on localhost using ruby's `File.write`. This will
4
+ # only write files to the machine you run Bolt on. Use `write_file()` to write
5
+ # to remote targets.
6
+ Puppet::Functions.create_function(:'file::write') do
7
+ # @param filename Absolute path.
8
+ # @param content File content to write.
9
+ # @example Write a file to disk
10
+ # file::write('C:/Users/me/report', $apply_result.first.report)
11
+ dispatch :write do
12
+ required_param 'String', :filename
13
+ required_param 'String', :content
14
+ return_type 'Undef'
15
+ end
16
+
17
+ def write(filename, content)
18
+ # Send Analytics Report
19
+ Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)
20
+
21
+ File.write(filename, content)
22
+ nil
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/util/format'
4
+
5
+ # Log a debugging message.
6
+ #
7
+ # Messages logged at this level typically include detailed information about
8
+ # what a plan is doing. For example, you might log a message at the `debug`
9
+ # level that shows what value is returned from a function invocation.
10
+ #
11
+ # See [Logs](logs.md) for more information about Bolt's log levels.
12
+ #
13
+ # > **Note:** Not available in apply block
14
+ Puppet::Functions.create_function(:'log::debug') do
15
+ # Log a debugging message.
16
+ # @param message The message to log.
17
+ # @example Log a debugging message
18
+ # log::debug("Function frogsay returned: ${result}")
19
+ dispatch :log_debug do
20
+ param 'Any', :message
21
+ return_type 'Undef'
22
+ end
23
+
24
+ def log_debug(message)
25
+ unless Puppet[:tasks]
26
+ raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
27
+ Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
28
+ action: 'log::debug'
29
+ )
30
+ end
31
+
32
+ Puppet.lookup(:bolt_executor).tap do |executor|
33
+ executor.report_function_call(self.class.name)
34
+ executor.publish_event(type: :log, level: :debug, message: Bolt::Util::Format.stringify(message))
35
+ end
36
+
37
+ nil
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/util/format'
4
+
5
+ # Log an error message.
6
+ #
7
+ # Messages logged at this level typically indicate that the plan encountered an
8
+ # error that can be recovered from. For example, you might log a message at the
9
+ # `error` level if you want to inform the user an action running on a target
10
+ # failed but that the plan will continue running.
11
+ #
12
+ # See [Logs](logs.md) for more information about Bolt's log levels.
13
+ #
14
+ # > **Note:** Not available in apply block
15
+ Puppet::Functions.create_function(:'log::error') do
16
+ # Log an error message.
17
+ # @param message The message to log.
18
+ # @example Log an error message
19
+ # log::error("The HTTP request returned an error, continuing the plan: ${result}")
20
+ dispatch :log_error do
21
+ param 'Any', :message
22
+ return_type 'Undef'
23
+ end
24
+
25
+ def log_error(message)
26
+ unless Puppet[:tasks]
27
+ raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
28
+ Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
29
+ action: 'log::error'
30
+ )
31
+ end
32
+
33
+ Puppet.lookup(:bolt_executor).tap do |executor|
34
+ executor.report_function_call(self.class.name)
35
+ executor.publish_event(type: :log, level: :error, message: Bolt::Util::Format.stringify(message))
36
+ end
37
+
38
+ nil
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/util/format'
4
+
5
+ # Log a fatal message.
6
+ #
7
+ # Messages logged at this level indicate that the plan encountered an error that
8
+ # could not be recovered from. For example, you might log a message at the
9
+ # `fatal` level if a service is unavailable and the plan cannot continue running
10
+ # without it.
11
+ #
12
+ # See [Logs](logs.md) for more information about Bolt's log levels.
13
+ #
14
+ # > **Note:** Not available in apply block
15
+ Puppet::Functions.create_function(:'log::fatal') do
16
+ # Log a fatal message.
17
+ # @param message The message to log.
18
+ # @example Log a fatal message
19
+ # log::fatal("The service is unavailable, unable to continue running: ${result}")
20
+ dispatch :log_fatal do
21
+ param 'Any', :message
22
+ return_type 'Undef'
23
+ end
24
+
25
+ def log_fatal(message)
26
+ unless Puppet[:tasks]
27
+ raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
28
+ Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
29
+ action: 'log::fatal'
30
+ )
31
+ end
32
+
33
+ Puppet.lookup(:bolt_executor).tap do |executor|
34
+ executor.report_function_call(self.class.name)
35
+ executor.publish_event(type: :log, level: :fatal, message: Bolt::Util::Format.stringify(message))
36
+ end
37
+
38
+ nil
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/util/format'
4
+
5
+ # Log an info message.
6
+ #
7
+ # Messages logged at this level typically include high-level information about
8
+ # what a plan is doing. For example, you might log a message at the `info` level
9
+ # that informs users that the plan is reading a file on disk.
10
+ #
11
+ # See [Logs](logs.md) for more information about Bolt's log levels.
12
+ #
13
+ # > **Note:** Not available in apply block
14
+ Puppet::Functions.create_function(:'log::info') do
15
+ # Log an info message.
16
+ # @param message The message to log.
17
+ # @example Log an info message
18
+ # log::info("Reading network device command file ${file}.")
19
+ dispatch :log_info do
20
+ param 'Any', :message
21
+ return_type 'Undef'
22
+ end
23
+
24
+ def log_info(message)
25
+ unless Puppet[:tasks]
26
+ raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
27
+ Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
28
+ action: 'log::info'
29
+ )
30
+ end
31
+
32
+ Puppet.lookup(:bolt_executor).tap do |executor|
33
+ executor.report_function_call(self.class.name)
34
+ executor.publish_event(type: :log, level: :info, message: Bolt::Util::Format.stringify(message))
35
+ end
36
+
37
+ nil
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/util/format'
4
+
5
+ # Log a trace message.
6
+ #
7
+ # Messages logged at this level typically include the most detailed information
8
+ # about what a plan is doing. For example, you might log a message at the `trace`
9
+ # level that describes how a plan is manipulating data.
10
+ #
11
+ # See [Logs](logs.md) for more information about Bolt's log levels.
12
+ #
13
+ # > **Note:** Not available in apply block
14
+ Puppet::Functions.create_function(:'log::trace') do
15
+ # Log a trace message.
16
+ # @param message The message to log.
17
+ # @example Log a trace message
18
+ # log::trace("Creating Target object with data ${data} from file ${file}")
19
+ dispatch :log_trace do
20
+ param 'Any', :message
21
+ return_type 'Undef'
22
+ end
23
+
24
+ def log_trace(message)
25
+ unless Puppet[:tasks]
26
+ raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
27
+ Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
28
+ action: 'log::trace'
29
+ )
30
+ end
31
+
32
+ Puppet.lookup(:bolt_executor).tap do |executor|
33
+ executor.report_function_call(self.class.name)
34
+ executor.publish_event(type: :log, level: :trace, message: Bolt::Util::Format.stringify(message))
35
+ end
36
+
37
+ nil
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/util/format'
4
+
5
+ # Log a warning message.
6
+ #
7
+ # Messages logged at this level typically include messages about deprecated
8
+ # behavior or potentially harmful situations that might affect the plan run.
9
+ # For example, you might log a message at the `warn` level if you are
10
+ # planning to make a breaking change to your plan in a future release and
11
+ # want to notify users.
12
+ #
13
+ # See [Logs](logs.md) for more information about Bolt's log levels.
14
+ #
15
+ # > **Note:** Not available in apply block
16
+ Puppet::Functions.create_function(:'log::warn') do
17
+ # Log a warning message.
18
+ # @param message The message to log.
19
+ # @example Log a warning message
20
+ # log::warn('This plan will no longer install the package in a future release.')
21
+ dispatch :log_warn do
22
+ param 'Any', :message
23
+ return_type 'Undef'
24
+ end
25
+
26
+ def log_warn(message)
27
+ unless Puppet[:tasks]
28
+ raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
29
+ Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
30
+ action: 'log::warn'
31
+ )
32
+ end
33
+
34
+ Puppet.lookup(:bolt_executor).tap do |executor|
35
+ executor.report_function_call(self.class.name)
36
+ executor.publish_event(type: :log, level: :warn, message: Bolt::Util::Format.stringify(message))
37
+ end
38
+
39
+ nil
40
+ end
41
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/util/format'
4
+
5
+ # Output a message for the user.
6
+ #
7
+ # This will print a message to stdout when using the human output format,
8
+ # and print to stderr when using the json output format. Messages are
9
+ # also logged at the `info` level. For more information about logs, see
10
+ # [Logs](logs.md).
11
+ #
12
+ # > **Note:** Not available in apply block
13
+ Puppet::Functions.create_function(:'out::message') do
14
+ # Output a message.
15
+ # @param message The message to output.
16
+ # @example Print a message
17
+ # out::message('Something went wrong')
18
+ dispatch :output_message do
19
+ param 'Any', :message
20
+ return_type 'Undef'
21
+ end
22
+
23
+ def output_message(message)
24
+ unless Puppet[:tasks]
25
+ raise Puppet::ParseErrorWithIssue
26
+ .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'out::message')
27
+ end
28
+
29
+ Puppet.lookup(:bolt_executor).tap do |executor|
30
+ executor.report_function_call(self.class.name)
31
+ executor.publish_event(type: :message, message: Bolt::Util::Format.stringify(message), level: :info)
32
+ end
33
+
34
+ nil
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/util/format'
4
+
5
+ # Output a message for the user when running in verbose mode.
6
+ #
7
+ # This will print a message to stdout when using the human output format,
8
+ # and print to stderr when using the json output format. Messages are
9
+ # also logged at the `debug` level. For more information about logs, see
10
+ # [Logs](logs.md).
11
+ #
12
+ # > **Note:** Not available in apply block
13
+ Puppet::Functions.create_function(:'out::verbose') do
14
+ # @param message The message to output.
15
+ # @example Print a message
16
+ # out::verbose('Something went wrong')
17
+ dispatch :output_verbose do
18
+ param 'Any', :message
19
+ return_type 'Undef'
20
+ end
21
+
22
+ def output_verbose(message)
23
+ unless Puppet[:tasks]
24
+ raise Puppet::ParseErrorWithIssue
25
+ .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'out::verbose')
26
+ end
27
+
28
+ Puppet.lookup(:bolt_executor).tap do |executor|
29
+ executor.report_function_call(self.class.name)
30
+ executor.publish_event(type: :verbose, message: Bolt::Util::Format.stringify(message), level: :debug)
31
+ end
32
+
33
+ nil
34
+ end
35
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/error'
4
+
5
+ # Display a menu prompt and wait for a response. Continues to prompt
6
+ # until an option from the menu is selected.
7
+ #
8
+ # > **Note:** Not available in apply block
9
+ Puppet::Functions.create_function(:'prompt::menu') do
10
+ # Select from a list of options.
11
+ # @param prompt The prompt to display.
12
+ # @param menu A list of options to choose from.
13
+ # @param options A hash of additional options.
14
+ # @option options [String] default The default option to return if the user does not provide
15
+ # input or if standard in (stdin) is not a tty. Must be an option present in the menu.
16
+ # @return The selected option.
17
+ # @example Prompt the user to select from a list of options
18
+ # $selection = prompt::menu('Select a fruit', ['apple', 'banana', 'carrot'])
19
+ # @example Prompt the user to select from a list of options with a default value
20
+ # $selection = prompt::menu('Select environment', ['development', 'production'], 'default' => 'development')
21
+ dispatch :prompt_menu_array do
22
+ param 'String', :prompt
23
+ param 'Array[Variant[Target, Data]]', :menu
24
+ optional_param 'Hash[String[1], Variant[Target, Data]]', :options
25
+ return_type 'Variant[Target, Data]'
26
+ end
27
+
28
+ # Select from a list of options with custom inputs.
29
+ # @param prompt The prompt to display.
30
+ # @param menu A hash of options to choose from, where keys are the input used to select a value.
31
+ # @param options A hash of additional options.
32
+ # @option options [String] default The default option to return if the user does not provide
33
+ # input or if standard in (stdin) is not a tty. Must be an option present in the menu.
34
+ # @return The selected option.
35
+ # @example Prompt the user to select from a list of options with custom inputs
36
+ # $menu = { 'y' => 'yes', 'n' => 'no' }
37
+ # $selection = prompt::menu('Install Puppet?', $menu)
38
+ dispatch :prompt_menu do
39
+ param 'String', :prompt
40
+ param 'Hash[String[1], Variant[Target, Data]]', :menu
41
+ optional_param 'Hash[String[1], Variant[Target, Data]]', :options
42
+ return_type 'Variant[TargetSpec, Data]'
43
+ end
44
+
45
+ def prompt_menu_array(prompt, menu, options = {})
46
+ menu_hash = menu.map.with_index { |value, index| [(index + 1).to_s, value] }.to_h
47
+ prompt_menu(prompt, menu_hash, options)
48
+ end
49
+
50
+ def prompt_menu(prompt, menu, options = {})
51
+ unless Puppet[:tasks]
52
+ raise Puppet::ParseErrorWithIssue
53
+ .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
54
+ action: 'prompt::menu')
55
+ end
56
+
57
+ options = options.transform_keys(&:to_sym)
58
+ executor = Puppet.lookup(:bolt_executor)
59
+
60
+ # Send analytics report
61
+ executor.report_function_call(self.class.name)
62
+
63
+ # Error if there are no options
64
+ if menu.empty?
65
+ raise Bolt::ValidationError, "Menu cannot be empty"
66
+ end
67
+
68
+ # Error if the default value is not on the menu
69
+ if options.key?(:default) && !menu.value?(options[:default])
70
+ raise Bolt::ValidationError, "Default value '#{options[:default]}' is not one of the provided menu options"
71
+ end
72
+
73
+ # The first prompt should include the menu
74
+ to_prompt = format_menu(menu) + prompt
75
+
76
+ # Request input from the user until they provide a valid option
77
+ loop do
78
+ selection = executor.prompt(to_prompt, options)
79
+
80
+ return menu[selection] if menu.key?(selection)
81
+ return selection if options.key?(:default) && options[:default] == selection
82
+
83
+ # Only reprint the prompt, not the menu
84
+ to_prompt = "Invalid option, try again. #{prompt}"
85
+ end
86
+ end
87
+
88
+ # Builds the menu string. Aligns all the values by padding input keys.
89
+ #
90
+ private def format_menu(menu)
91
+ # Find the longest input and add 2 for wrapping parenthesis
92
+ key_length = menu.keys.max_by(&:length).length + 2
93
+
94
+ menu_string = +''
95
+
96
+ menu.each do |key, value|
97
+ key = "(#{key})".ljust(key_length)
98
+ menu_string << "#{key} #{value}\n"
99
+ end
100
+
101
+ menu_string
102
+ end
103
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bolt/error'
4
+
5
+ # Display a prompt and wait for a response.
6
+ #
7
+ # > **Note:** Not available in apply block
8
+ Puppet::Functions.create_function(:prompt) do
9
+ # @param prompt The prompt to display.
10
+ # @param options A hash of additional options.
11
+ # @option options [Boolean] sensitive Disable echo back and mark the response as sensitive.
12
+ # The returned value will be wrapped by the `Sensitive` data type. To access the raw
13
+ # value, use the `unwrap` function (i.e. `$sensitive_value.unwrap`).
14
+ # @option options [String] default The default value to return if the user does not provide
15
+ # input or if stdin is not a tty.
16
+ # @return The response to the prompt.
17
+ # @example Prompt the user if plan execution should continue
18
+ # $response = prompt('Continue executing plan? [Y\N]')
19
+ # @example Prompt the user for sensitive information
20
+ # $password = prompt('Enter your password', 'sensitive' => true)
21
+ # out::message("Password is: ${password.unwrap}")
22
+ # @example Prompt the user and provide a default value
23
+ # $user = prompt('Enter your login username', 'default' => 'root')
24
+ # @example Prompt the user for sensitive information, returning a sensitive default if one is not provided
25
+ # $token = prompt('Enter token', 'default' => lookup('default_token'), 'sensitive' => true)
26
+ # out::message("Token is: ${token.unwrap}")
27
+ # @example Prompt the user and fail with a custom message if no input was provided
28
+ # $response = prompt('Enter your name', 'default' => '')
29
+ # if $response.empty {
30
+ # fail_plan('Must provide your name')
31
+ # }
32
+ dispatch :prompt do
33
+ param 'String', :prompt
34
+ optional_param 'Hash[String[1], Any]', :options
35
+ return_type 'Variant[String, Sensitive]'
36
+ end
37
+
38
+ def prompt(prompt, options = {})
39
+ unless Puppet[:tasks]
40
+ raise Puppet::ParseErrorWithIssue
41
+ .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
42
+ action: 'prompt')
43
+ end
44
+
45
+ options = options.transform_keys(&:to_sym)
46
+ executor = Puppet.lookup(:bolt_executor)
47
+
48
+ # Send analytics report
49
+ executor.report_function_call(self.class.name)
50
+
51
+ # Require default to be a string value
52
+ if options.key?(:default) && !options[:default].is_a?(String)
53
+ raise Bolt::ValidationError, "Option 'default' must be a string"
54
+ end
55
+
56
+ response = executor.prompt(prompt, options)
57
+
58
+ # If sensitive, wrap it
59
+ if options[:sensitive]
60
+ Puppet::Pops::Types::PSensitiveType::Sensitive.new(response)
61
+ else
62
+ response
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Get an environment variable.
4
+ Puppet::Functions.create_function(:'system::env') do
5
+ # @param name Environment variable name.
6
+ # @return The environment variable's value.
7
+ # @example Get the USER environment variable
8
+ # system::env('USER')
9
+ dispatch :env do
10
+ required_param 'String', :name
11
+ return_type 'Optional[String]'
12
+ end
13
+
14
+ def env(name)
15
+ # Send analytics report
16
+ Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)
17
+
18
+ ENV[name]
19
+ end
20
+ end
data/exe/bolt ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bolt'
5
+ require 'bolt/cli'
6
+
7
+ Thread.current[:name] ||= 'main'
8
+ cli = Bolt::CLI.new(ARGV)
9
+ begin
10
+ opts = cli.parse
11
+ exitcode = cli.execute(opts)
12
+ exit exitcode
13
+ rescue Bolt::CLIExit
14
+ exit
15
+ rescue Bolt::Error => e
16
+ exit e.error_code
17
+ end
@@ -0,0 +1,27 @@
1
+ ---
2
+ topic: debugging
3
+ guide: |
4
+ When Bolt isn't behaving as expected, there are a few helpful commands and
5
+ logs that can help identify common issues. The first place to look is in
6
+ `<PROJECT>/bolt-debug.log`, which contains debug-level logs from the last Bolt
7
+ run. This log file includes where the Bolt project was loaded from, the
8
+ location of any configuration or inventory files that were loaded, and the
9
+ modulepath that modules were loaded from.
10
+
11
+ If you're having issues with loading targets or target configuration, you
12
+ can see the list of resolved Bolt target names by running `bolt inventory
13
+ show` on *nix systems or `Get-BoltInventory` in PowerShell. To see the
14
+ resolved configuration for each target, run the command with the `--detail` or
15
+ `-Detail` options.
16
+
17
+ Lastly, if you're having trouble loading Bolt content you can use `bolt
18
+ module show` on *nix systems or `Get-BoltModule` in PowerShell to see the list
19
+ of loaded modules, including where they were loaded from. You can also use
20
+ `bolt task show` or `Get-BoltTask` to list loaded tasks, and `bolt plan show`
21
+ or `Get-BoltPlan` to list loaded plans.
22
+
23
+ Visit the linked documentation for more in-depth troubleshooting help for
24
+ specific issues.
25
+
26
+ documentation:
27
+ - https://pup.pt/bolt-troubleshooting
@@ -0,0 +1,23 @@
1
+ ---
2
+ topic: inventory
3
+ guide: |
4
+ The inventory describes the targets that you run Bolt commands on, along
5
+ with any data and configuration for the targets. Targets in an inventory can
6
+ belong to one or more groups, allowing you to share data and configuration
7
+ across multiple targets and to specify multiple targets for your Bolt
8
+ commands without the need to list each target individually.
9
+
10
+ In most cases, Bolt loads the inventory from an inventory file in your Bolt
11
+ project. The inventory file is a YAML file named 'inventory.yaml'. Because
12
+ Bolt loads the inventory file from a Bolt project, you must have an existing
13
+ project configuration file named 'bolt-project.yaml' alongside the inventory
14
+ file.
15
+
16
+ When Bolt loads inventory, it loads the entire inventory, not just the
17
+ groups and targets specified on the command line. If you've defined a
18
+ target in multiple groups, this might result in target configuration that
19
+ is different than expected.
20
+
21
+ documentation:
22
+ - https://pup.pt/bolt-inventory
23
+ - https://pup.pt/bolt-inventory-reference
data/guides/links.yaml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ topic: links
3
+ guide: |
4
+ Bolt documentation https://bolt.guide
5
+ Ask a question in #bolt https://slack.puppet.com/
6
+ Contribute at https://github.com/puppetlabs/bolt/
7
+ Getting Started Guide https://pup.pt/bolt-getting-started
8
+ Reference Documentation https://pup.pt/bolt-reference
9
+ Troubleshooting Bolt https://pup.pt/bolt-troubleshooting
10
+ Bolt Developer Updates https://pup.pt/bolt-dev-updates
11
+ Bolt Changelog https://pup.pt/bolt-changelog
12
+ Bolt Examples https://pup.pt/bolt-examples
@@ -0,0 +1,17 @@
1
+ ---
2
+ topic: logging
3
+ guide: |
4
+ Bolt prints messages both to the console and to log files. Messages can
5
+ either come from Bolt's 'outputter', which logs user-facing messages like
6
+ progress and results, or from the 'logger', which logs warnings, errors, and
7
+ log-structured output to log files. Both of these message streams are
8
+ configurable.
9
+
10
+ By default, Bolt logs to the console at 'warn' level and writes a log file to
11
+ '<project>/bolt-debug.log' at 'debug' level. Unless you are running a plan,
12
+ Bolt runs in verbose mode by default.
13
+
14
+ To learn more about projects, see the 'project' guide.
15
+
16
+ documentation:
17
+ - https://pup.pt/bolt-logging