bolt 0.17.1 → 0.17.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +25 -13
  3. data/lib/bolt/cli.rb +45 -15
  4. data/lib/bolt/config.rb +48 -132
  5. data/lib/bolt/executor.rb +3 -10
  6. data/lib/bolt/inventory.rb +15 -1
  7. data/lib/bolt/puppetdb.rb +11 -0
  8. data/lib/bolt/puppetdb/client.rb +68 -0
  9. data/lib/bolt/puppetdb/config.rb +76 -0
  10. data/lib/bolt/target.rb +5 -4
  11. data/lib/bolt/transport/base.rb +11 -2
  12. data/lib/bolt/transport/local.rb +11 -5
  13. data/lib/bolt/transport/orch.rb +16 -5
  14. data/lib/bolt/transport/ssh.rb +32 -1
  15. data/lib/bolt/transport/ssh/connection.rb +17 -10
  16. data/lib/bolt/transport/winrm.rb +18 -1
  17. data/lib/bolt/transport/winrm/connection.rb +15 -16
  18. data/lib/bolt/util.rb +15 -0
  19. data/lib/bolt/version.rb +1 -1
  20. data/lib/bolt_ext/puppetdb_inventory.rb +5 -135
  21. data/vendored/facter/lib/facter/ec2/rest.rb +1 -1
  22. data/vendored/hiera/lib/hiera/version.rb +1 -1
  23. data/vendored/puppet/lib/puppet/application/agent.rb +1 -3
  24. data/vendored/puppet/lib/puppet/application/apply.rb +2 -4
  25. data/vendored/puppet/lib/puppet/application/cert.rb +6 -1
  26. data/vendored/puppet/lib/puppet/application/device.rb +100 -13
  27. data/vendored/puppet/lib/puppet/application/facts.rb +5 -0
  28. data/vendored/puppet/lib/puppet/application/lookup.rb +11 -1
  29. data/vendored/puppet/lib/puppet/configurer.rb +17 -4
  30. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -1
  31. data/vendored/puppet/lib/puppet/datatypes.rb +1 -1
  32. data/vendored/puppet/lib/puppet/defaults.rb +1 -1
  33. data/vendored/puppet/lib/puppet/environments.rb +2 -2
  34. data/vendored/puppet/lib/puppet/error.rb +6 -3
  35. data/vendored/puppet/lib/puppet/external/dot.rb +0 -7
  36. data/vendored/puppet/lib/puppet/external/nagios/parser.rb +1 -1
  37. data/vendored/puppet/lib/puppet/face/config.rb +41 -8
  38. data/vendored/puppet/lib/puppet/face/epp.rb +30 -5
  39. data/vendored/puppet/lib/puppet/face/facts.rb +49 -0
  40. data/vendored/puppet/lib/puppet/face/help.rb +33 -35
  41. data/vendored/puppet/lib/puppet/face/man.rb +55 -12
  42. data/vendored/puppet/lib/puppet/face/parser.rb +30 -3
  43. data/vendored/puppet/lib/puppet/file_bucket/file.rb +0 -2
  44. data/vendored/puppet/lib/puppet/file_serving/base.rb +10 -10
  45. data/vendored/puppet/lib/puppet/functions.rb +1 -3
  46. data/vendored/puppet/lib/puppet/functions/alert.rb +1 -1
  47. data/vendored/puppet/lib/puppet/functions/all.rb +6 -6
  48. data/vendored/puppet/lib/puppet/functions/annotate.rb +10 -10
  49. data/vendored/puppet/lib/puppet/functions/any.rb +6 -6
  50. data/vendored/puppet/lib/puppet/functions/assert_type.rb +4 -4
  51. data/vendored/puppet/lib/puppet/functions/binary_file.rb +14 -2
  52. data/vendored/puppet/lib/puppet/functions/break.rb +31 -2
  53. data/vendored/puppet/lib/puppet/functions/call.rb +4 -4
  54. data/vendored/puppet/lib/puppet/functions/contain.rb +19 -3
  55. data/vendored/puppet/lib/puppet/functions/convert_to.rb +6 -5
  56. data/vendored/puppet/lib/puppet/functions/crit.rb +1 -1
  57. data/vendored/puppet/lib/puppet/functions/debug.rb +1 -1
  58. data/vendored/puppet/lib/puppet/functions/defined.rb +11 -9
  59. data/vendored/puppet/lib/puppet/functions/dig.rb +26 -2
  60. data/vendored/puppet/lib/puppet/functions/each.rb +8 -8
  61. data/vendored/puppet/lib/puppet/functions/emerg.rb +1 -1
  62. data/vendored/puppet/lib/puppet/functions/empty.rb +79 -0
  63. data/vendored/puppet/lib/puppet/functions/err.rb +1 -1
  64. data/vendored/puppet/lib/puppet/functions/filter.rb +7 -7
  65. data/vendored/puppet/lib/puppet/functions/find_file.rb +15 -1
  66. data/vendored/puppet/lib/puppet/functions/flatten.rb +64 -0
  67. data/vendored/puppet/lib/puppet/functions/hiera.rb +6 -6
  68. data/vendored/puppet/lib/puppet/functions/hiera_array.rb +6 -6
  69. data/vendored/puppet/lib/puppet/functions/hiera_hash.rb +6 -6
  70. data/vendored/puppet/lib/puppet/functions/hiera_include.rb +8 -8
  71. data/vendored/puppet/lib/puppet/functions/include.rb +28 -2
  72. data/vendored/puppet/lib/puppet/functions/info.rb +1 -1
  73. data/vendored/puppet/lib/puppet/functions/inline_epp.rb +2 -2
  74. data/vendored/puppet/lib/puppet/functions/join.rb +56 -0
  75. data/vendored/puppet/lib/puppet/functions/keys.rb +25 -0
  76. data/vendored/puppet/lib/puppet/functions/length.rb +44 -0
  77. data/vendored/puppet/lib/puppet/functions/lest.rb +39 -1
  78. data/vendored/puppet/lib/puppet/functions/map.rb +10 -9
  79. data/vendored/puppet/lib/puppet/functions/match.rb +6 -6
  80. data/vendored/puppet/lib/puppet/functions/new.rb +995 -2
  81. data/vendored/puppet/lib/puppet/functions/next.rb +1 -1
  82. data/vendored/puppet/lib/puppet/functions/notice.rb +1 -1
  83. data/vendored/puppet/lib/puppet/functions/reduce.rb +6 -6
  84. data/vendored/puppet/lib/puppet/functions/regsubst.rb +9 -3
  85. data/vendored/puppet/lib/puppet/functions/require.rb +36 -2
  86. data/vendored/puppet/lib/puppet/functions/return.rb +1 -1
  87. data/vendored/puppet/lib/puppet/functions/reverse_each.rb +71 -2
  88. data/vendored/puppet/lib/puppet/functions/slice.rb +23 -9
  89. data/vendored/puppet/lib/puppet/functions/split.rb +12 -10
  90. data/vendored/puppet/lib/puppet/functions/step.rb +73 -1
  91. data/vendored/puppet/lib/puppet/functions/strftime.rb +176 -2
  92. data/vendored/puppet/lib/puppet/functions/then.rb +65 -2
  93. data/vendored/puppet/lib/puppet/functions/tree_each.rb +19 -19
  94. data/vendored/puppet/lib/puppet/functions/type.rb +42 -1
  95. data/vendored/puppet/lib/puppet/functions/unique.rb +13 -13
  96. data/vendored/puppet/lib/puppet/functions/unwrap.rb +8 -4
  97. data/vendored/puppet/lib/puppet/functions/values.rb +25 -0
  98. data/vendored/puppet/lib/puppet/functions/versioncmp.rb +1 -1
  99. data/vendored/puppet/lib/puppet/functions/warning.rb +1 -1
  100. data/vendored/puppet/lib/puppet/functions/with.rb +6 -4
  101. data/vendored/puppet/lib/puppet/indirector/certificate_status/file.rb +1 -1
  102. data/vendored/puppet/lib/puppet/indirector/facts/facter.rb +1 -3
  103. data/vendored/puppet/lib/puppet/indirector/facts/rest.rb +21 -0
  104. data/vendored/puppet/lib/puppet/indirector/facts/yaml.rb +0 -4
  105. data/vendored/puppet/lib/puppet/indirector/file_content/http.rb +3 -1
  106. data/vendored/puppet/lib/puppet/indirector/indirection.rb +5 -3
  107. data/vendored/puppet/lib/puppet/indirector/request.rb +6 -2
  108. data/vendored/puppet/lib/puppet/module/task.rb +2 -2
  109. data/vendored/puppet/lib/puppet/module_tool/tar/mini.rb +57 -4
  110. data/vendored/puppet/lib/puppet/network/authconfig.rb +1 -1
  111. data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +1 -0
  112. data/vendored/puppet/lib/puppet/network/resolver.rb +1 -2
  113. data/vendored/puppet/lib/puppet/node.rb +4 -3
  114. data/vendored/puppet/lib/puppet/parser/compiler.rb +12 -5
  115. data/vendored/puppet/lib/puppet/parser/compiler/catalog_validator/env_relationship_validator.rb +1 -1
  116. data/vendored/puppet/lib/puppet/parser/functions/fqdn_rand.rb +15 -4
  117. data/vendored/puppet/lib/puppet/parser/functions/new.rb +31 -46
  118. data/vendored/puppet/lib/puppet/parser/parser_factory.rb +1 -1
  119. data/vendored/puppet/lib/puppet/parser/resource.rb +1 -1
  120. data/vendored/puppet/lib/puppet/parser/type_loader.rb +11 -11
  121. data/vendored/puppet/lib/puppet/pops/evaluator/closure.rb +1 -1
  122. data/vendored/puppet/lib/puppet/pops/evaluator/collector_transformer.rb +1 -1
  123. data/vendored/puppet/lib/puppet/pops/evaluator/epp_evaluator.rb +2 -2
  124. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_resource_support.rb +2 -2
  125. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +5 -2
  126. data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +1 -1
  127. data/vendored/puppet/lib/puppet/pops/issue_reporter.rb +18 -1
  128. data/vendored/puppet/lib/puppet/pops/issues.rb +6 -3
  129. data/vendored/puppet/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +1 -2
  130. data/vendored/puppet/lib/puppet/pops/loader/ruby_function_instantiator.rb +1 -2
  131. data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +4 -4
  132. data/vendored/puppet/lib/puppet/pops/loader/type_definition_instantiator.rb +4 -1
  133. data/vendored/puppet/lib/puppet/pops/loaders.rb +18 -7
  134. data/vendored/puppet/lib/puppet/pops/lookup/global_data_provider.rb +1 -1
  135. data/vendored/puppet/lib/puppet/pops/model/factory.rb +6 -3
  136. data/vendored/puppet/lib/puppet/pops/model/model_tree_dumper.rb +4 -0
  137. data/vendored/puppet/lib/puppet/pops/model/pn_transformer.rb +400 -0
  138. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +1 -1
  139. data/vendored/puppet/lib/puppet/pops/parser/heredoc_support.rb +1 -1
  140. data/vendored/puppet/lib/puppet/pops/parser/lexer_support.rb +3 -2
  141. data/vendored/puppet/lib/puppet/pops/parser/locator.rb +0 -2
  142. data/vendored/puppet/lib/puppet/pops/parser/pn_parser.rb +316 -0
  143. data/vendored/puppet/lib/puppet/pops/pcore.rb +17 -17
  144. data/vendored/puppet/lib/puppet/pops/pn.rb +236 -0
  145. data/vendored/puppet/lib/puppet/pops/resource/resource_type_impl.rb +1 -1
  146. data/vendored/puppet/lib/puppet/pops/types/class_loader.rb +6 -3
  147. data/vendored/puppet/lib/puppet/pops/types/implementation_registry.rb +28 -35
  148. data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +3 -3
  149. data/vendored/puppet/lib/puppet/pops/types/p_timespan_type.rb +2 -2
  150. data/vendored/puppet/lib/puppet/pops/types/p_type_set_type.rb +24 -1
  151. data/vendored/puppet/lib/puppet/pops/types/ruby_generator.rb +3 -4
  152. data/vendored/puppet/lib/puppet/pops/types/type_calculator.rb +1 -1
  153. data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +0 -4
  154. data/vendored/puppet/lib/puppet/pops/types/type_mismatch_describer.rb +1 -1
  155. data/vendored/puppet/lib/puppet/pops/types/type_parser.rb +14 -7
  156. data/vendored/puppet/lib/puppet/pops/types/types.rb +1 -1
  157. data/vendored/puppet/lib/puppet/pops/utils.rb +2 -2
  158. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +6 -2
  159. data/vendored/puppet/lib/puppet/provider/group/groupadd.rb +3 -1
  160. data/vendored/puppet/lib/puppet/provider/group/windows_adsi.rb +4 -7
  161. data/vendored/puppet/lib/puppet/provider/nameservice.rb +3 -3
  162. data/vendored/puppet/lib/puppet/provider/package/dnf.rb +1 -1
  163. data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
  164. data/vendored/puppet/lib/puppet/provider/package/pacman.rb +4 -4
  165. data/vendored/puppet/lib/puppet/provider/package/pip.rb +3 -3
  166. data/vendored/puppet/lib/puppet/provider/package/pkgdmg.rb +3 -3
  167. data/vendored/puppet/lib/puppet/provider/package/pkgutil.rb +2 -2
  168. data/vendored/puppet/lib/puppet/provider/package/portage.rb +9 -9
  169. data/vendored/puppet/lib/puppet/provider/package/zypper.rb +2 -2
  170. data/vendored/puppet/lib/puppet/provider/service/base.rb +1 -1
  171. data/vendored/puppet/lib/puppet/provider/service/smf.rb +3 -2
  172. data/vendored/puppet/lib/puppet/provider/user/useradd.rb +6 -2
  173. data/vendored/puppet/lib/puppet/provider/user/windows_adsi.rb +1 -1
  174. data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +3 -2
  175. data/vendored/puppet/lib/puppet/reference/configuration.rb +2 -0
  176. data/vendored/puppet/lib/puppet/reference/type.rb +11 -11
  177. data/vendored/puppet/lib/puppet/resource.rb +1 -1
  178. data/vendored/puppet/lib/puppet/resource/capability_finder.rb +2 -2
  179. data/vendored/puppet/lib/puppet/resource/catalog.rb +2 -2
  180. data/vendored/puppet/lib/puppet/resource/status.rb +9 -2
  181. data/vendored/puppet/lib/puppet/resource/type.rb +1 -1
  182. data/vendored/puppet/lib/puppet/settings.rb +31 -19
  183. data/vendored/puppet/lib/puppet/settings/base_setting.rb +5 -0
  184. data/vendored/puppet/lib/puppet/settings/config_file.rb +1 -1
  185. data/vendored/puppet/lib/puppet/settings/ttl_setting.rb +5 -0
  186. data/vendored/puppet/lib/puppet/ssl/certificate_factory.rb +2 -2
  187. data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +0 -2
  188. data/vendored/puppet/lib/puppet/transaction/additional_resource_generator.rb +2 -2
  189. data/vendored/puppet/lib/puppet/transaction/event.rb +1 -1
  190. data/vendored/puppet/lib/puppet/transaction/report.rb +1 -1
  191. data/vendored/puppet/lib/puppet/type.rb +9 -13
  192. data/vendored/puppet/lib/puppet/type/augeas.rb +2 -2
  193. data/vendored/puppet/lib/puppet/type/cron.rb +11 -6
  194. data/vendored/puppet/lib/puppet/type/exec.rb +1 -1
  195. data/vendored/puppet/lib/puppet/type/file.rb +4 -5
  196. data/vendored/puppet/lib/puppet/type/host.rb +1 -1
  197. data/vendored/puppet/lib/puppet/type/k5login.rb +30 -54
  198. data/vendored/puppet/lib/puppet/type/package.rb +3 -3
  199. data/vendored/puppet/lib/puppet/type/schedule.rb +12 -12
  200. data/vendored/puppet/lib/puppet/type/scheduled_task.rb +2 -2
  201. data/vendored/puppet/lib/puppet/type/ssh_authorized_key.rb +5 -5
  202. data/vendored/puppet/lib/puppet/type/sshkey.rb +2 -2
  203. data/vendored/puppet/lib/puppet/type/tidy.rb +9 -2
  204. data/vendored/puppet/lib/puppet/type/user.rb +1 -1
  205. data/vendored/puppet/lib/puppet/type/yumrepo.rb +25 -4
  206. data/vendored/puppet/lib/puppet/type/zfs.rb +4 -0
  207. data/vendored/puppet/lib/puppet/util.rb +0 -4
  208. data/vendored/puppet/lib/puppet/util/backups.rb +1 -1
  209. data/vendored/puppet/lib/puppet/util/http_proxy.rb +4 -2
  210. data/vendored/puppet/lib/puppet/util/inifile.rb +3 -4
  211. data/vendored/puppet/lib/puppet/util/log.rb +2 -5
  212. data/vendored/puppet/lib/puppet/util/network_device/cisco/facts.rb +1 -1
  213. data/vendored/puppet/lib/puppet/util/reference.rb +1 -8
  214. data/vendored/puppet/lib/puppet/util/tagging.rb +1 -1
  215. data/vendored/puppet/lib/puppet/util/warnings.rb +0 -2
  216. data/vendored/puppet/lib/puppet/util/windows/adsi.rb +15 -18
  217. data/vendored/puppet/lib/puppet/util/windows/com.rb +2 -1
  218. data/vendored/puppet/lib/puppet/util/windows/file.rb +2 -2
  219. data/vendored/puppet/lib/puppet/util/windows/principal.rb +7 -6
  220. data/vendored/puppet/lib/puppet/util/windows/sid.rb +60 -7
  221. data/vendored/puppet/lib/puppet/util/windows/taskscheduler.rb +0 -9
  222. data/vendored/puppet/lib/puppet/version.rb +1 -1
  223. data/vendored/puppet/lib/puppet_pal.rb +53 -48
  224. metadata +15 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8759e96b6a18784b8ede93ee47d24a108c69081d
4
- data.tar.gz: 2555ed2cef120bca77905ca535a41b09ef12df07
3
+ metadata.gz: c9ea02d63dd2b45747f5eda9d07187f39842332f
4
+ data.tar.gz: 3768ff96fafe4b6cb9d05fdad94c17ce3809e2be
5
5
  SHA512:
6
- metadata.gz: a65bc900d11f643783028dc846af43c2f115f4311c50c7b03630e091cf353e75a3b5ee79162fdaf0531a1e5c8b939d12c3a3838f7b94e373dd6ef0faec3f4133
7
- data.tar.gz: 3334b078eb1012f1af15a75a22e3a1691fa578360eeddc0f9f3b239e0bf7f8ea3f876641693a3a1966a214419107ab81b935a28a19051f0d6190c5a5fc7b3c51
6
+ metadata.gz: 26863769817e4f0b644041dc32b2eda8c961d75ab34bc805db0ff497ff8c624672c5d3d6051cdd6add2fa921e862310d9236879cacf61aa35144fd795f159c03
7
+ data.tar.gz: 6b767b8e2dab9368e0bd5bc7feee4b397f18a39005eca646d2bad44e3a400bdca5009f1e6d1e51d1688ab8265e02996a2b127840e918cdd405c618a6fe00a52c
@@ -41,12 +41,6 @@ Puppet::Functions.create_function(:run_task) do
41
41
  )
42
42
  end
43
43
 
44
- # TODO: use the compiler injection once PUP-8237 lands
45
- task_signature = Puppet::Pal::ScriptCompiler.new(closure_scope.compiler).task_signature(task_name)
46
- if task_signature.nil?
47
- raise with_stack(:UNKNOWN_TASK, Bolt::Error.unknown_task(task_name))
48
- end
49
-
50
44
  executor = Puppet.lookup(:bolt_executor) { nil }
51
45
  inventory = Puppet.lookup(:bolt_inventory) { nil }
52
46
  unless executor && inventory && Puppet.features.bolt?
@@ -55,18 +49,38 @@ Puppet::Functions.create_function(:run_task) do
55
49
  )
56
50
  end
57
51
 
52
+ # Ensure that given targets are all Target instances
53
+ targets = inventory.get_targets(targets)
54
+
58
55
  use_args = task_args.reject { |k, _| k.start_with?('_') }
59
56
 
60
- task_signature.runnable_with?(use_args) do |mismatch_message|
61
- raise with_stack(:TYPE_MISMATCH, mismatch_message)
62
- end || (raise with_stack(:TYPE_MISMATCH, 'Task parameters do not match'))
57
+ # Don't bother loading the local task definition if all targets use the 'pcp' transport
58
+ # and the local-validation option is set to false for all of them
59
+ if !targets.empty? && targets.all? { |t| t.protocol == 'pcp' && t.options['local-validation'] == false }
60
+ # create a fake task
61
+ task = Puppet::Pops::Types::TypeFactory.task.from_hash(
62
+ 'name' => task_name,
63
+ 'executable' => '',
64
+ 'supports_noop' => true
65
+ )
66
+ else
67
+ # TODO: use the compiler injection once PUP-8237 lands
68
+ task_signature = Puppet::Pal::ScriptCompiler.new(closure_scope.compiler).task_signature(task_name)
69
+ if task_signature.nil?
70
+ raise with_stack(:UNKNOWN_TASK, Bolt::Error.unknown_task(task_name))
71
+ end
72
+
73
+ task_signature.runnable_with?(use_args) do |mismatch_message|
74
+ raise with_stack(:TYPE_MISMATCH, mismatch_message)
75
+ end || (raise with_stack(:TYPE_MISMATCH, 'Task parameters do not match'))
76
+
77
+ task = task_signature.task
78
+ end
63
79
 
64
80
  unless Puppet::Pops::Types::TypeFactory.data.instance?(use_args)
65
81
  raise with_stack(:TYPE_NOT_DATA, 'Task parameters is not of type Data')
66
82
  end
67
83
 
68
- task = task_signature.task
69
-
70
84
  if executor.noop
71
85
  if task.supports_noop
72
86
  use_args['_noop'] = true
@@ -75,8 +89,6 @@ Puppet::Functions.create_function(:run_task) do
75
89
  end
76
90
  end
77
91
 
78
- # Ensure that given targets are all Target instances
79
- targets = inventory.get_targets(targets)
80
92
  if targets.empty?
81
93
  Bolt::ResultSet.new([])
82
94
  else
@@ -10,6 +10,7 @@ require 'bolt/executor'
10
10
  require 'bolt/inventory'
11
11
  require 'bolt/logger'
12
12
  require 'bolt/outputter'
13
+ require 'bolt/puppetdb'
13
14
  require 'bolt/pal'
14
15
  require 'bolt/target'
15
16
  require 'bolt/version'
@@ -129,6 +130,10 @@ Available options are:
129
130
  '* port defaults to `5985` or `5986` for WinRM, based on the --[no-]ssl setting') do |nodes|
130
131
  @options[:nodes] << get_arg_input(nodes)
131
132
  end.extend(SwitchHider)
133
+ @query = define('-q', '--query QUERY',
134
+ 'Query PuppetDB to determine the targets') do |query|
135
+ @options[:query] = query
136
+ end.extend(SwitchHider)
132
137
  define('-u', '--user USER',
133
138
  'User to authenticate as (Optional)') do |user|
134
139
  @options[:user] = user
@@ -146,7 +151,7 @@ Available options are:
146
151
  end
147
152
  define('--private-key KEY',
148
153
  'Private ssh key to authenticate with (Optional)') do |key|
149
- @options[:key] = key
154
+ @options[:'private-key'] = key
150
155
  end
151
156
  define('--tmpdir DIR',
152
157
  'The directory to upload and execute temporary files on the target (Optional)') do |tmpdir|
@@ -159,7 +164,7 @@ Available options are:
159
164
  end
160
165
  define('--connect-timeout TIMEOUT', Integer,
161
166
  'Connection timeout (Optional)') do |timeout|
162
- @options[:connect_timeout] = timeout
167
+ @options[:'connect-timeout'] = timeout
163
168
  end
164
169
  define('--modulepath MODULES',
165
170
  'List of directories containing modules, ' \
@@ -177,28 +182,28 @@ Available options are:
177
182
  end
178
183
  define('--[no-]host-key-check',
179
184
  'Check host keys with SSH') do |host_key_check|
180
- @options[:host_key_check] = host_key_check
185
+ @options[:'host-key-check'] = host_key_check
181
186
  end
182
187
  define('--[no-]ssl',
183
188
  'Use SSL with WinRM') do |ssl|
184
189
  @options[:ssl] = ssl
185
190
  end
186
- define('--transport TRANSPORT', TRANSPORTS.map(&:to_s),
187
- 'Specify a default transport: ' << TRANSPORTS.join(', ')) do |t|
191
+ define('--transport TRANSPORT', TRANSPORTS.keys.map(&:to_s),
192
+ 'Specify a default transport: ' << TRANSPORTS.keys.join(', ')) do |t|
188
193
  @options[:transport] = t
189
194
  end
190
195
  define('--run-as USER',
191
196
  'User to run as using privilege escalation') do |user|
192
- @options[:run_as] = user
197
+ @options[:'run-as'] = user
193
198
  end
194
199
  define('--sudo-password [PASSWORD]',
195
200
  'Password for privilege escalation') do |password|
196
201
  if password.nil?
197
202
  STDOUT.print "Please enter your privilege escalation password: "
198
- @options[:sudo_password] = STDIN.noecho(&:gets).chomp
203
+ @options[:'sudo-password'] = STDIN.noecho(&:gets).chomp
199
204
  STDOUT.puts
200
205
  else
201
- @options[:sudo_password] = password
206
+ @options[:'sudo-password'] = password
202
207
  end
203
208
  end
204
209
  define('--configfile CONFIG_PATH',
@@ -207,6 +212,9 @@ Available options are:
207
212
  end
208
213
  define('--inventoryfile INVENTORY_PATH',
209
214
  'Specify where to load the inventory file from') do |path|
215
+ if ENV.include?(Bolt::Inventory::ENVIRONMENT_VAR)
216
+ raise Bolt::CLIError, "Cannot pass inventory file when #{Bolt::Inventory::ENVIRONMENT_VAR} is set"
217
+ end
210
218
  @options[:inventoryfile] = path
211
219
  end
212
220
  define_tail('--[no-]tty',
@@ -235,9 +243,14 @@ Available options are:
235
243
  end
236
244
 
237
245
  def update
246
+ # show the --nodes and --query switches by default
247
+ @nodes.hide = @query.hide = false
248
+
238
249
  # Update the banner according to the mode
239
250
  self.banner = case @options[:mode]
240
251
  when 'plan'
252
+ # don't show the --nodes and --query switches in the plan help
253
+ @nodes.hide = @query.hide = true
241
254
  PLAN_HELP
242
255
  when 'command'
243
256
  COMMAND_HELP
@@ -250,10 +263,6 @@ Available options are:
250
263
  else
251
264
  BANNER
252
265
  end
253
-
254
- # Only show the --nodes switch in the help message produced by
255
- # the #help method when not dealing with plans
256
- @nodes.hide = (@options[:mode] == 'plan')
257
266
  end
258
267
 
259
268
  def parse_params(params)
@@ -367,7 +376,12 @@ Available options are:
367
376
 
368
377
  # After validation, initialize inventory and targets. Errors here are better to catch early.
369
378
  unless options[:action] == 'show' || options[:mode] == 'plan'
370
- options[:targets] = inventory.get_targets(options[:nodes]) if options[:nodes]
379
+ if options[:query]
380
+ nodes = query_puppetdb_nodes(options[:query])
381
+ options[:targets] = inventory.get_targets(nodes)
382
+ else
383
+ options[:targets] = inventory.get_targets(options[:nodes])
384
+ end
371
385
  end
372
386
 
373
387
  options
@@ -412,8 +426,12 @@ Available options are:
412
426
  end
413
427
  end
414
428
 
415
- if options[:nodes].empty? && options[:mode] != 'plan' && options[:action] != 'show'
416
- raise Bolt::CLIError, "Option '--nodes' must be specified"
429
+ if options[:mode] != 'plan' && options[:action] != 'show'
430
+ if options[:nodes].empty? && options[:query].nil?
431
+ raise Bolt::CLIError, "Targets must be specified with '--nodes' or '--query'"
432
+ elsif options[:nodes].any? && options[:query]
433
+ raise Bolt::CLIError, "Only one of '--nodes' or '--query' may be specified"
434
+ end
417
435
  end
418
436
 
419
437
  if options[:noop] && (options[:mode] != 'task' || options[:action] != 'run')
@@ -432,6 +450,18 @@ Available options are:
432
450
  raise Bolt::CLIError, "Unknown argument '#{e.args.first}'"
433
451
  end
434
452
 
453
+ def puppetdb_client
454
+ return @puppetdb_client if @puppetdb_client
455
+ puppetdb_config = Bolt::PuppetDB::Config.new(nil, config.puppetdb)
456
+ @puppetdb_client = Bolt::PuppetDB::Client.from_config(puppetdb_config)
457
+ end
458
+
459
+ def query_puppetdb_nodes(query)
460
+ puppetdb_client.query_certnames(query)
461
+ rescue StandardError => e
462
+ raise Bolt::CLIError, "Could not retrieve targets from PuppetDB: #{e}"
463
+ end
464
+
435
465
  def execute(options)
436
466
  message = nil
437
467
 
@@ -1,9 +1,18 @@
1
1
  require 'yaml'
2
- require 'bolt/cli'
3
2
  require 'logging'
3
+ require 'bolt/cli'
4
+ require 'bolt/transport/ssh'
5
+ require 'bolt/transport/winrm'
6
+ require 'bolt/transport/orch'
7
+ require 'bolt/transport/local'
4
8
 
5
9
  module Bolt
6
- TRANSPORTS = %i[ssh winrm pcp local].freeze
10
+ TRANSPORTS = {
11
+ ssh: Bolt::Transport::SSH,
12
+ winrm: Bolt::Transport::WinRM,
13
+ pcp: Bolt::Transport::Orch,
14
+ local: Bolt::Transport::Local
15
+ }.freeze
7
16
 
8
17
  Config = Struct.new(
9
18
  :concurrency,
@@ -12,6 +21,7 @@ module Bolt
12
21
  :log_level,
13
22
  :log,
14
23
  :modulepath,
24
+ :puppetdb,
15
25
  :transport,
16
26
  :transports
17
27
  ) do
@@ -20,27 +30,29 @@ module Bolt
20
30
  concurrency: 100,
21
31
  transport: 'ssh',
22
32
  format: 'human',
23
- modulepath: []
33
+ modulepath: [],
34
+ puppetdb: {}
24
35
  }.freeze
25
36
 
26
- TRANSPORT_OPTIONS = %i[host_key_check password run_as sudo_password extensions
27
- ssl key tty tmpdir user connect_timeout cacert
28
- token-file task-environment service-url].freeze
37
+ TRANSPORT_OPTIONS = %i[password run-as sudo-password extensions
38
+ private-key tty tmpdir user connect-timeout
39
+ cacert token-file service-url].freeze
29
40
 
30
41
  TRANSPORT_DEFAULTS = {
31
- connect_timeout: 10,
32
- tty: false
42
+ 'connect-timeout' => 10,
43
+ 'tty' => false
33
44
  }.freeze
34
45
 
35
46
  TRANSPORT_SPECIFIC_DEFAULTS = {
36
47
  ssh: {
37
- host_key_check: true
48
+ 'host-key-check' => true
38
49
  },
39
50
  winrm: {
40
- ssl: true
51
+ 'ssl' => true
41
52
  },
42
53
  pcp: {
43
- :"task-environment" => 'production'
54
+ 'task-environment' => 'production',
55
+ 'local-validation' => false
44
56
  },
45
57
  local: {}
46
58
  }.freeze
@@ -55,10 +67,9 @@ module Bolt
55
67
  self[:log]['console'] ||= {}
56
68
 
57
69
  self[:transports] ||= {}
58
- TRANSPORTS.each do |transport|
59
- unless self[:transports][transport]
60
- self[:transports][transport] = {}
61
- end
70
+ TRANSPORTS.each_key do |transport|
71
+ self[:transports][transport] ||= {}
72
+
62
73
  TRANSPORT_DEFAULTS.each do |k, v|
63
74
  unless self[:transports][transport][k]
64
75
  self[:transports][transport][k] = v
@@ -109,74 +120,16 @@ module Bolt
109
120
  self[:modulepath] = data['modulepath'].split(File::PATH_SEPARATOR)
110
121
  end
111
122
 
112
- if data['inventoryfile']
113
- self[:inventoryfile] = data['inventoryfile']
114
- end
115
-
116
- if data['concurrency']
117
- self[:concurrency] = data['concurrency']
118
- end
119
-
120
- if data['format']
121
- self[:format] = data['format']
122
- end
123
-
124
- if data['ssh']
125
- if data['ssh']['private-key']
126
- self[:transports][:ssh][:key] = data['ssh']['private-key']
127
- end
128
- if data['ssh'].key?('host-key-check')
129
- self[:transports][:ssh][:host_key_check] = data['ssh']['host-key-check']
130
- end
131
- if data['ssh']['connect-timeout']
132
- self[:transports][:ssh][:connect_timeout] = data['ssh']['connect-timeout']
133
- end
134
- if data['ssh']['tmpdir']
135
- self[:transports][:ssh][:tmpdir] = data['ssh']['tmpdir']
136
- end
137
- if data['ssh']['run-as']
138
- self[:transports][:ssh][:run_as] = data['ssh']['run-as']
139
- end
140
- end
141
-
142
- if data['winrm']
143
- if data['winrm']['connect-timeout']
144
- self[:transports][:winrm][:connect_timeout] = data['winrm']['connect-timeout']
145
- end
146
- if data['winrm'].key?('ssl')
147
- self[:transports][:winrm][:ssl] = data['winrm']['ssl']
148
- end
149
- if data['winrm']['tmpdir']
150
- self[:transports][:winrm][:tmpdir] = data['winrm']['tmpdir']
151
- end
152
- if data['winrm']['cacert']
153
- self[:transports][:winrm][:cacert] = data['winrm']['cacert']
154
- end
155
- if data['winrm']['extensions']
156
- # Accept a single entry or a list, ensure each is prefixed with '.'
157
- self[:transports][:winrm][:extensions] =
158
- [data['winrm']['extensions']].flatten.map { |ext| ext[0] != '.' ? '.' + ext : ext }
123
+ %w[inventoryfile concurrency format puppetdb].each do |key|
124
+ if data[key]
125
+ self[key.to_sym] = data[key]
159
126
  end
160
127
  end
161
128
 
162
- if data['pcp']
163
- if data['pcp']['service-url']
164
- self[:transports][:pcp][:"service-url"] = data['pcp']['service-url']
165
- end
166
- if data['pcp']['cacert']
167
- self[:transports][:pcp][:cacert] = data['pcp']['cacert']
168
- end
169
- if data['pcp']['token-file']
170
- self[:transports][:pcp][:"token-file"] = data['pcp']['token-file']
171
- end
172
- if data['pcp']['task-environment']
173
- self[:transports][:pcp][:"task-environment"] = data['pcp']['task-environment']
174
- end
175
- end
176
-
177
- if data['local']
178
- if data['local']['tmpdir']
179
- self[:transports][:local][:tmpdir] = data['local']['tmpdir']
129
+ TRANSPORTS.each do |key, impl|
130
+ if data[key.to_s]
131
+ selected = data[key.to_s].select { |k| impl.options.include?(k) }
132
+ self[:transports][key].merge!(selected)
180
133
  end
181
134
  end
182
135
  end
@@ -198,23 +151,22 @@ module Bolt
198
151
  self[:log]['console'][:level] = :info
199
152
  end
200
153
 
201
- TRANSPORT_OPTIONS.each do |key|
202
- TRANSPORTS.each do |transport|
203
- unless %i[ssl host_key_check task-environment].any? { |k| k == key }
204
- self[:transports][transport][key] = options[key] if options[key]
205
- next
206
- end
207
- if key == :ssl && transport == :winrm
208
- # this defaults to true so we need to check the presence of the key
209
- self[:transports][transport][key] = options[key] if options.key?(key)
210
- next
211
- elsif key == :host_key_check && transport == :ssh
212
- # this defaults to true so we need to check the presence of the key
213
- self[:transports][transport][key] = options[key] if options.key?(key)
214
- next
154
+ TRANSPORTS.each_key do |transport|
155
+ transport = self[:transports][transport]
156
+ TRANSPORT_OPTIONS.each do |key|
157
+ if options[key]
158
+ transport[key.to_s] = Bolt::Util.walk_keys(options[key], &:to_s)
215
159
  end
216
160
  end
217
161
  end
162
+
163
+ if options.key?(:ssl) # this defaults to true so we need to check the presence of the key
164
+ self[:transports][:winrm]['ssl'] = options[:ssl]
165
+ end
166
+
167
+ if options.key?(:'host-key-check') # this defaults to true so we need to check the presence of the key
168
+ self[:transports][:ssh]['host-key-check'] = options[:'host-key-check']
169
+ end
218
170
  end
219
171
 
220
172
  def update_from_inventory(data)
@@ -223,19 +175,6 @@ module Bolt
223
175
  if data['transport']
224
176
  self[:transport] = data['transport']
225
177
  end
226
-
227
- # Add options that aren't allowed in a config file, but are allowed in inventory
228
- %w[user password port].each do |opt|
229
- (TRANSPORTS - [:pcp]).each do |transport|
230
- if data[transport.to_s] && data[transport.to_s][opt]
231
- self[:transports][transport][opt.to_sym] = data[transport.to_s][opt]
232
- end
233
- end
234
- end
235
-
236
- if data['ssh'] && data['ssh']['sudo-password']
237
- self[:transports][:ssh][:sudo_password] = data['ssh']['sudo-password']
238
- end
239
178
  end
240
179
 
241
180
  def transport_conf
@@ -244,10 +183,6 @@ module Bolt
244
183
  end
245
184
 
246
185
  def validate
247
- TRANSPORTS.each do |transport|
248
- self[:transports][transport]
249
- end
250
-
251
186
  self[:log].each_pair do |name, params|
252
187
  if params.key?(:level) && !Bolt::Logger.valid_level?(params[:level])
253
188
  raise Bolt::CLIError,
@@ -262,27 +197,8 @@ module Bolt
262
197
  raise Bolt::CLIError, "Unsupported format: '#{self[:format]}'"
263
198
  end
264
199
 
265
- if self[:transports][:ssh][:sudo_password] && self[:transports][:ssh][:run_as].nil?
266
- @logger.warn("--sudo-password will not be used without specifying a " \
267
- "user to escalate to with --run-as")
268
- end
269
-
270
- host_key = self[:transports][:ssh][:host_key_check]
271
- unless !!host_key == host_key
272
- raise Bolt::CLIError, 'host-key-check option must be a Boolean true or false'
273
- end
274
-
275
- ssl_flag = self[:transports][:winrm][:ssl]
276
- unless !!ssl_flag == ssl_flag
277
- raise Bolt::CLIError, 'ssl option must be a Boolean true or false'
278
- end
279
-
280
- self[:transports].each_value do |v|
281
- timeout_value = v[:connect_timeout]
282
- unless timeout_value.is_a?(Integer) || timeout_value.nil?
283
- error_msg = "connect-timeout value must be an Integer, received #{timeout_value}:#{timeout_value.class}"
284
- raise Bolt::CLIError, error_msg
285
- end
200
+ TRANSPORTS.each do |transport, impl|
201
+ impl.validate(self[:transports][transport])
286
202
  end
287
203
  end
288
204
  end