puppet 6.0.0 → 6.1.0

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 (259) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +20 -20
  4. data/Guardfile.example +76 -0
  5. data/LICENSE +189 -4
  6. data/README.md +3 -3
  7. data/Rakefile +5 -2
  8. data/ext/solaris/smf/svc-puppetd +8 -1
  9. data/ext/solaris/smf/svc-puppetmasterd +8 -1
  10. data/lib/puppet/application/apply.rb +100 -59
  11. data/lib/puppet/application/cert.rb +4 -114
  12. data/lib/puppet/application/device.rb +48 -32
  13. data/lib/puppet/application/script.rb +1 -1
  14. data/lib/puppet/application/ssl.rb +135 -51
  15. data/lib/puppet/application.rb +5 -0
  16. data/lib/puppet/configurer.rb +2 -3
  17. data/lib/puppet/defaults.rb +33 -49
  18. data/lib/puppet/etc.rb +20 -0
  19. data/lib/puppet/face/config.rb +3 -3
  20. data/lib/puppet/face/key.rb +1 -1
  21. data/lib/puppet/face/node/clean.rb +0 -1
  22. data/lib/puppet/feature/base.rb +1 -1
  23. data/lib/puppet/file_bucket/dipper.rb +1 -1
  24. data/lib/puppet/file_serving/fileset.rb +1 -1
  25. data/lib/puppet/functions/abs.rb +1 -1
  26. data/lib/puppet/functions/new.rb +1 -1
  27. data/lib/puppet/module/task.rb +29 -38
  28. data/lib/puppet/pal/catalog_compiler.rb +96 -0
  29. data/lib/puppet/pal/compiler.rb +221 -0
  30. data/lib/puppet/pal/function_signature.rb +52 -0
  31. data/lib/puppet/pal/json_catalog_encoder.rb +67 -0
  32. data/lib/puppet/pal/pal_api.rb +15 -0
  33. data/lib/puppet/pal/pal_impl.rb +523 -0
  34. data/lib/puppet/pal/plan_signature.rb +71 -0
  35. data/lib/puppet/pal/script_compiler.rb +71 -0
  36. data/lib/puppet/pal/task_signature.rb +58 -0
  37. data/lib/puppet/parser/catalog_compiler.rb +24 -0
  38. data/lib/puppet/parser/compiler.rb +3 -1
  39. data/lib/puppet/parser/functions/generate.rb +7 -6
  40. data/lib/puppet/plugins/configuration.rb +5 -1
  41. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +3 -1
  42. data/lib/puppet/pops/evaluator/deferred_resolver.rb +3 -0
  43. data/lib/puppet/pops/evaluator/evaluator_impl.rb +5 -1
  44. data/lib/puppet/pops/evaluator/external_syntax_support.rb +3 -3
  45. data/lib/puppet/pops/evaluator/runtime3_converter.rb +2 -2
  46. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +19 -10
  47. data/lib/puppet/pops/loader/task_instantiator.rb +13 -70
  48. data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
  49. data/lib/puppet/pops/parser/lexer2.rb +1 -1
  50. data/lib/puppet/pops/pcore.rb +10 -33
  51. data/lib/puppet/pops/serialization/to_data_converter.rb +9 -1
  52. data/lib/puppet/pops/serialization.rb +1 -0
  53. data/lib/puppet/pops/types/p_timespan_type.rb +2 -2
  54. data/lib/puppet/pops/types/string_converter.rb +18 -4
  55. data/lib/puppet/pops/validation/checker4_0.rb +17 -2
  56. data/lib/puppet/provider/exec.rb +59 -57
  57. data/lib/puppet/provider/group/aix.rb +18 -2
  58. data/lib/puppet/provider/group/windows_adsi.rb +7 -3
  59. data/lib/puppet/provider/nameservice.rb +1 -25
  60. data/lib/puppet/provider/package/dnf.rb +2 -0
  61. data/lib/puppet/provider/package/pkgng.rb +37 -21
  62. data/lib/puppet/provider/package/portage.rb +2 -2
  63. data/lib/puppet/provider/package/windows/exe_package.rb +16 -10
  64. data/lib/puppet/provider/package/windows/msi_package.rb +8 -0
  65. data/lib/puppet/provider/package/windows/package.rb +9 -1
  66. data/lib/puppet/provider/package/windows.rb +2 -2
  67. data/lib/puppet/provider/package/yum.rb +1 -1
  68. data/lib/puppet/provider/parsedfile.rb +25 -4
  69. data/lib/puppet/provider/service/launchd.rb +19 -3
  70. data/lib/puppet/provider/service/smf.rb +54 -0
  71. data/lib/puppet/provider/service/systemd.rb +19 -0
  72. data/lib/puppet/provider/service/upstart.rb +1 -0
  73. data/lib/puppet/provider/service/windows.rb +22 -5
  74. data/lib/puppet/provider/user/aix.rb +48 -2
  75. data/lib/puppet/provider/user/useradd.rb +2 -10
  76. data/lib/puppet/provider/user/windows_adsi.rb +9 -1
  77. data/lib/puppet/resource/catalog.rb +1 -5
  78. data/lib/puppet/resource.rb +3 -1
  79. data/lib/puppet/ssl/host.rb +26 -16
  80. data/lib/puppet/syntax_checkers/epp.rb +34 -0
  81. data/lib/puppet/syntax_checkers/pp.rb +34 -0
  82. data/lib/puppet/transaction/event_manager.rb +13 -1
  83. data/lib/puppet/transaction/persistence.rb +1 -1
  84. data/lib/puppet/transaction/resource_harness.rb +3 -1
  85. data/lib/puppet/type/group.rb +29 -1
  86. data/lib/puppet/type/package.rb +5 -1
  87. data/lib/puppet/type/resources.rb +12 -2
  88. data/lib/puppet/type/schedule.rb +7 -0
  89. data/lib/puppet/type/service.rb +12 -0
  90. data/lib/puppet/type/user.rb +5 -2
  91. data/lib/puppet/type.rb +6 -0
  92. data/lib/puppet/util/command_line.rb +2 -3
  93. data/lib/puppet/util/execution.rb +15 -1
  94. data/lib/puppet/util/filetype.rb +56 -8
  95. data/lib/puppet/util/log/destinations.rb +3 -2
  96. data/lib/puppet/util/logging.rb +3 -2
  97. data/lib/puppet/util/posix.rb +15 -0
  98. data/lib/puppet/util/selinux.rb +1 -1
  99. data/lib/puppet/util/storage.rb +12 -0
  100. data/lib/puppet/util/windows/adsi.rb +79 -2
  101. data/lib/puppet/util/windows/api_types.rb +1 -1
  102. data/lib/puppet/util/windows/process.rb +23 -3
  103. data/lib/puppet/util/windows/registry.rb +29 -5
  104. data/lib/puppet/util/windows/security.rb +14 -0
  105. data/lib/puppet/util/windows/service.rb +294 -74
  106. data/lib/puppet/util/windows/user.rb +3 -5
  107. data/lib/puppet/util.rb +7 -3
  108. data/lib/puppet/version.rb +1 -1
  109. data/lib/puppet.rb +1 -0
  110. data/lib/puppet_pal.rb +5 -1099
  111. data/locales/ja/puppet.po +952 -986
  112. data/locales/puppet.pot +592 -347
  113. data/man/man5/puppet.conf.5 +26 -31
  114. data/man/man8/puppet-agent.8 +1 -1
  115. data/man/man8/puppet-apply.8 +1 -1
  116. data/man/man8/puppet-catalog.8 +1 -1
  117. data/man/man8/puppet-config.8 +4 -4
  118. data/man/man8/puppet-describe.8 +1 -1
  119. data/man/man8/puppet-device.8 +23 -19
  120. data/man/man8/puppet-doc.8 +1 -1
  121. data/man/man8/puppet-epp.8 +1 -1
  122. data/man/man8/puppet-facts.8 +1 -1
  123. data/man/man8/puppet-filebucket.8 +1 -1
  124. data/man/man8/puppet-generate.8 +1 -1
  125. data/man/man8/puppet-help.8 +1 -1
  126. data/man/man8/puppet-key.8 +2 -2
  127. data/man/man8/puppet-lookup.8 +1 -1
  128. data/man/man8/puppet-man.8 +1 -1
  129. data/man/man8/puppet-module.8 +1 -1
  130. data/man/man8/puppet-node.8 +1 -1
  131. data/man/man8/puppet-parser.8 +1 -1
  132. data/man/man8/puppet-plugin.8 +1 -1
  133. data/man/man8/puppet-report.8 +1 -1
  134. data/man/man8/puppet-resource.8 +1 -1
  135. data/man/man8/puppet-script.8 +1 -1
  136. data/man/man8/puppet-ssl.8 +26 -3
  137. data/man/man8/puppet-status.8 +1 -1
  138. data/man/man8/puppet.8 +2 -2
  139. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/usee/lib/puppet/parser/functions/bad_func_load.rb +11 -0
  140. data/spec/fixtures/unit/provider/package/pkgng/pkg.query +7 -1
  141. data/spec/fixtures/unit/provider/package/pkgng/pkg.query.zsh +1 -0
  142. data/spec/fixtures/unit/provider/service/smf/svcs_fmri.out +6 -0
  143. data/spec/fixtures/unit/provider/service/smf/svcs_multiple_fmris.out +13 -0
  144. data/spec/integration/application/apply_spec.rb +4 -1
  145. data/spec/integration/parser/collection_spec.rb +4 -8
  146. data/spec/integration/provider/service/windows_spec.rb +5 -5
  147. data/spec/integration/ssl/key_spec.rb +0 -4
  148. data/spec/integration/transaction_spec.rb +559 -0
  149. data/spec/integration/type/file_spec.rb +6 -6
  150. data/spec/integration/util/windows/registry_spec.rb +39 -0
  151. data/spec/integration/util/windows/security_spec.rb +10 -7
  152. data/spec/integration/util/windows/user_spec.rb +37 -17
  153. data/spec/lib/puppet/test_ca.rb +1 -1
  154. data/spec/spec_helper.rb +1 -1
  155. data/spec/unit/agent_spec.rb +2 -2
  156. data/spec/unit/application/apply_spec.rb +55 -2
  157. data/spec/unit/application/device_spec.rb +10 -7
  158. data/spec/unit/application/face_base_spec.rb +1 -1
  159. data/spec/unit/application/lookup_spec.rb +2 -1
  160. data/spec/unit/application/ssl_spec.rb +178 -109
  161. data/spec/unit/application_spec.rb +29 -11
  162. data/spec/unit/configurer/downloader_spec.rb +1 -1
  163. data/spec/unit/configurer_spec.rb +16 -5
  164. data/spec/unit/etc_spec.rb +25 -0
  165. data/spec/unit/face/node_spec.rb +1 -3
  166. data/spec/unit/face/parser_spec.rb +15 -0
  167. data/spec/unit/file_serving/fileset_spec.rb +11 -11
  168. data/spec/unit/functions/logging_spec.rb +10 -3
  169. data/spec/unit/indirector/catalog/json_spec.rb +9 -3
  170. data/spec/unit/indirector/yaml_spec.rb +1 -1
  171. data/spec/unit/network/http/connection_spec.rb +2 -2
  172. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +36 -0
  173. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +22 -4
  174. data/spec/unit/pops/loaders/loader_spec.rb +9 -17
  175. data/spec/unit/pops/loaders/loaders_spec.rb +48 -0
  176. data/spec/unit/pops/loaders/module_loaders_spec.rb +7 -7
  177. data/spec/unit/pops/parser/parse_heredoc_spec.rb +16 -0
  178. data/spec/unit/pops/serialization/to_from_hr_spec.rb +9 -0
  179. data/spec/unit/pops/types/p_timespan_type_spec.rb +22 -0
  180. data/spec/unit/pops/types/p_timestamp_type_spec.rb +19 -0
  181. data/spec/unit/pops/types/string_converter_spec.rb +25 -1
  182. data/spec/unit/pops/types/task_spec.rb +42 -116
  183. data/spec/unit/pops/validator/validator_spec.rb +24 -10
  184. data/spec/unit/provider/exec/posix_spec.rb +24 -0
  185. data/spec/unit/provider/group/aix_spec.rb +20 -6
  186. data/spec/unit/provider/group/ldap_spec.rb +22 -25
  187. data/spec/unit/provider/group/pw_spec.rb +7 -10
  188. data/spec/unit/provider/group/windows_adsi_spec.rb +42 -33
  189. data/spec/unit/provider/nameservice/directoryservice_spec.rb +97 -103
  190. data/spec/unit/provider/package/aix_spec.rb +5 -8
  191. data/spec/unit/provider/package/apt_spec.rb +3 -6
  192. data/spec/unit/provider/package/dnf_spec.rb +38 -25
  193. data/spec/unit/provider/package/dpkg_spec.rb +18 -21
  194. data/spec/unit/provider/package/freebsd_spec.rb +4 -7
  195. data/spec/unit/provider/package/gem_spec.rb +41 -41
  196. data/spec/unit/provider/package/hpux_spec.rb +7 -10
  197. data/spec/unit/provider/package/macports_spec.rb +13 -15
  198. data/spec/unit/provider/package/nim_spec.rb +3 -10
  199. data/spec/unit/provider/package/openbsd_spec.rb +14 -17
  200. data/spec/unit/provider/package/pip3_spec.rb +3 -6
  201. data/spec/unit/provider/package/pip_spec.rb +45 -49
  202. data/spec/unit/provider/package/pkgin_spec.rb +13 -18
  203. data/spec/unit/provider/package/pkgng_spec.rb +32 -27
  204. data/spec/unit/provider/package/puppet_gem_spec.rb +6 -9
  205. data/spec/unit/provider/package/tdnf_spec.rb +9 -12
  206. data/spec/unit/provider/package/windows/exe_package_spec.rb +3 -3
  207. data/spec/unit/provider/package/windows_spec.rb +4 -4
  208. data/spec/unit/provider/package/yum_spec.rb +30 -16
  209. data/spec/unit/provider/package/zypper_spec.rb +17 -19
  210. data/spec/unit/provider/service/bsd_spec.rb +7 -9
  211. data/spec/unit/provider/service/daemontools_spec.rb +12 -16
  212. data/spec/unit/provider/service/debian_spec.rb +6 -10
  213. data/spec/unit/provider/service/freebsd_spec.rb +2 -2
  214. data/spec/unit/provider/service/launchd_spec.rb +19 -0
  215. data/spec/unit/provider/service/openbsd_spec.rb +13 -17
  216. data/spec/unit/provider/service/rcng_spec.rb +2 -4
  217. data/spec/unit/provider/service/redhat_spec.rb +12 -11
  218. data/spec/unit/provider/service/runit_spec.rb +7 -14
  219. data/spec/unit/provider/service/smf_spec.rb +77 -13
  220. data/spec/unit/provider/service/src_spec.rb +11 -16
  221. data/spec/unit/provider/service/systemd_spec.rb +39 -1
  222. data/spec/unit/provider/service/windows_spec.rb +39 -7
  223. data/spec/unit/provider/user/aix_spec.rb +43 -2
  224. data/spec/unit/provider/user/hpux_spec.rb +3 -5
  225. data/spec/unit/provider/user/ldap_spec.rb +29 -32
  226. data/spec/unit/provider/user/pw_spec.rb +10 -13
  227. data/spec/unit/provider/user/useradd_spec.rb +2 -2
  228. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  229. data/spec/unit/puppet_pal_2pec.rb +6 -6
  230. data/spec/unit/puppet_pal_catalog_spec.rb +58 -0
  231. data/spec/unit/resource/catalog_spec.rb +2 -2
  232. data/spec/unit/resource_spec.rb +31 -0
  233. data/spec/unit/ssl/host_spec.rb +22 -1
  234. data/spec/unit/ssl/key_spec.rb +2 -4
  235. data/spec/unit/task_spec.rb +50 -5
  236. data/spec/unit/transaction/event_manager_spec.rb +12 -1
  237. data/spec/unit/transaction/persistence_spec.rb +4 -4
  238. data/spec/unit/transaction/resource_harness_spec.rb +18 -0
  239. data/spec/unit/type/group_spec.rb +11 -3
  240. data/spec/unit/type/resources_spec.rb +18 -0
  241. data/spec/unit/type/service_spec.rb +27 -1
  242. data/spec/unit/util/execution_spec.rb +77 -0
  243. data/spec/unit/util/filetype_spec.rb +13 -5
  244. data/spec/unit/util/log/destinations_spec.rb +10 -0
  245. data/spec/unit/util/logging_spec.rb +58 -41
  246. data/spec/unit/util/monkey_patches_spec.rb +18 -5
  247. data/spec/unit/util/posix_spec.rb +28 -0
  248. data/spec/unit/util/selinux_spec.rb +4 -0
  249. data/spec/unit/util/storage_spec.rb +107 -0
  250. data/spec/unit/util/suidmanager_spec.rb +1 -3
  251. data/spec/unit/util/windows/adsi_spec.rb +95 -0
  252. data/spec/unit/util/windows/service_spec.rb +377 -131
  253. metadata +24 -11
  254. data/ext/autotest/Rakefile +0 -8
  255. data/ext/autotest/config +0 -43
  256. data/ext/autotest/readme.rst +0 -16
  257. data/spec/fixtures/unit/provider/package/pkgng/pkg.info +0 -7
  258. data/spec/fixtures/unit/provider/package/pkgng/pkg.query_absent +0 -1
  259. data/spec/watchr.rb +0 -137
@@ -173,6 +173,11 @@ Copyright (c) 2011 Puppet Inc., LLC Licensed under the Apache 2.0 License
173
173
  else
174
174
  main
175
175
  end
176
+ ensure
177
+ if @profiler
178
+ Puppet::Util::Profiler.remove_profiler(@profiler)
179
+ @profiler.shutdown
180
+ end
176
181
  end
177
182
 
178
183
  def apply
@@ -189,53 +194,15 @@ Copyright (c) 2011 Puppet Inc., LLC Licensed under the Apache 2.0 License
189
194
  end
190
195
 
191
196
  def main
192
- # Set our code or file to use.
193
- if options[:code] or command_line.args.length == 0
194
- Puppet[:code] = options[:code] || STDIN.read
195
- else
196
- manifest = command_line.args.shift
197
- raise _("Could not find file %{manifest}") % { manifest: manifest } unless Puppet::FileSystem.exist?(manifest)
198
- Puppet.warning(_("Only one file can be applied per run. Skipping %{files}") % { files: command_line.args.join(', ') }) if command_line.args.size > 0
199
- end
200
-
201
- # splay if needed
202
- splay
197
+ manifest = get_manifest() # Get either a manifest or nil if apply should use content of Puppet[:code]
198
+ splay # splay if needed
199
+ facts = get_facts() # facts or nil
200
+ node = get_node() # node or error
201
+ apply_environment = get_configured_environment(node, manifest)
203
202
 
204
- unless Puppet[:node_name_fact].empty?
205
- # Collect our facts.
206
- unless facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value])
207
- raise _("Could not find facts for %{node}") % { node: Puppet[:node_name_value] }
208
- end
209
-
210
- Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
211
- facts.name = Puppet[:node_name_value]
212
- end
213
-
214
- # Find our Node
215
- unless node = Puppet::Node.indirection.find(Puppet[:node_name_value])
216
- raise _("Could not find node %{node}") % { node: Puppet[:node_name_value] }
217
- end
218
-
219
- configured_environment = node.environment || Puppet.lookup(:current_environment)
220
-
221
- apply_environment = manifest ?
222
- configured_environment.override_with(:manifest => manifest) :
223
- configured_environment
224
-
225
- # Modify the node descriptor to use the special apply_environment.
226
- # It is based on the actual environment from the node, or the locally
227
- # configured environment if the node does not specify one.
228
- # If a manifest file is passed on the command line, it overrides
229
- # the :manifest setting of the apply_environment.
230
- node.environment = apply_environment
231
-
232
- #TRANSLATORS "puppet apply" is a program command and should not be translated
203
+ # TRANSLATORS "puppet apply" is a program command and should not be translated
233
204
  Puppet.override({:current_environment => apply_environment}, _("For puppet apply")) do
234
- # Merge in the facts.
235
- node.merge(facts.values) if facts
236
-
237
- # Add server facts so $server_facts[environment] exists when doing a puppet apply
238
- node.add_server_facts({})
205
+ configure_node_facts(node, facts)
239
206
 
240
207
  # Allow users to load the classes that puppet agent creates.
241
208
  if options[:loadclasses]
@@ -287,7 +254,6 @@ Copyright (c) 2011 Puppet Inc., LLC Licensed under the Apache 2.0 License
287
254
  catalog.write_resource_file
288
255
  end
289
256
 
290
- #exit_status = Puppet.override(:loaders => Puppet::Pops::Loaders.new(apply_environment)) { apply_catalog(catalog) }
291
257
  apply_catalog(catalog)
292
258
  end
293
259
  if not exit_status
@@ -302,12 +268,6 @@ Copyright (c) 2011 Puppet Inc., LLC Licensed under the Apache 2.0 License
302
268
  exit(1)
303
269
  end
304
270
  end
305
-
306
- ensure
307
- if @profiler
308
- Puppet::Util::Profiler.remove_profiler(@profiler)
309
- @profiler.shutdown
310
- end
311
271
  end
312
272
 
313
273
  # Enable all of the most common test options.
@@ -323,6 +283,7 @@ Copyright (c) 2011 Puppet Inc., LLC Licensed under the Apache 2.0 License
323
283
 
324
284
  exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
325
285
 
286
+ handle_logdest_arg(Puppet[:logdest])
326
287
  Puppet::Util::Log.newdestination(:console) unless options[:setdest]
327
288
 
328
289
  Signal.trap(:INT) do
@@ -350,18 +311,98 @@ Copyright (c) 2011 Puppet Inc., LLC Licensed under the Apache 2.0 License
350
311
  private
351
312
 
352
313
  def read_catalog(text)
353
- format = Puppet::Resource::Catalog.default_format
354
- begin
355
- catalog = Puppet::Resource::Catalog.convert_from(format, text)
356
- rescue => detail
357
- raise Puppet::Error, _("Could not deserialize catalog from %{format}: %{detail}") % { format: format, detail: detail }, detail.backtrace
358
- end
314
+ facts = get_facts()
315
+ node = get_node()
316
+ configured_environment = get_configured_environment(node)
317
+
318
+ # TRANSLATORS "puppet apply" is a program command and should not be translated
319
+ Puppet.override({:current_environment => configured_environment}, _("For puppet apply")) do
320
+ configure_node_facts(node, facts)
321
+
322
+ # NOTE: Does not set rich_data = true automatically (which would ensure always reading catalog with rich data
323
+ # on (seemingly the right thing to do)), but that would remove the ability to test what happens when a
324
+ # rich catalog is processed without rich_data being turned on.
325
+ format = Puppet::Resource::Catalog.default_format
326
+ begin
327
+ catalog = Puppet::Resource::Catalog.convert_from(format, text)
328
+ rescue => detail
329
+ raise Puppet::Error, _("Could not deserialize catalog from %{format}: %{detail}") % { format: format, detail: detail }, detail.backtrace
330
+ end
331
+ # Resolve all deferred values and replace them / mutate the catalog
332
+ Puppet::Pops::Evaluator::DeferredResolver.resolve_and_replace(node.facts, catalog)
359
333
 
360
- catalog.to_ral
334
+ catalog.to_ral
335
+ end
361
336
  end
362
337
 
363
338
  def apply_catalog(catalog)
364
339
  configurer = Puppet::Configurer.new
365
340
  configurer.run(:catalog => catalog, :pluginsync => false)
366
341
  end
342
+
343
+ # Returns facts or nil
344
+ #
345
+ def get_facts()
346
+ facts = nil
347
+ unless Puppet[:node_name_fact].empty?
348
+ # Collect our facts.
349
+ unless facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value])
350
+ raise _("Could not find facts for %{node}") % { node: Puppet[:node_name_value] }
351
+ end
352
+
353
+ Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
354
+ facts.name = Puppet[:node_name_value]
355
+ end
356
+ facts
357
+ end
358
+
359
+ # Returns the node or raises and error if node not found.
360
+ #
361
+ def get_node()
362
+ node = Puppet::Node.indirection.find(Puppet[:node_name_value])
363
+ raise _("Could not find node %{node}") % { node: Puppet[:node_name_value] } unless node
364
+ node
365
+ end
366
+
367
+ # Returns either a manifest (filename) or nil if apply should use content of Puppet[:code]
368
+ #
369
+ def get_manifest()
370
+ manifest = nil
371
+ # Set our code or file to use.
372
+ if options[:code] or command_line.args.length == 0
373
+ Puppet[:code] = options[:code] || STDIN.read
374
+ else
375
+ manifest = command_line.args.shift
376
+ raise _("Could not find file %{manifest}") % { manifest: manifest } unless Puppet::FileSystem.exist?(manifest)
377
+ Puppet.warning(_("Only one file can be applied per run. Skipping %{files}") % { files: command_line.args.join(', ') }) if command_line.args.size > 0
378
+ end
379
+ manifest
380
+ end
381
+
382
+ # Returns a configured environment, if a manifest is given it overrides what is configured for the environment
383
+ # specified by the node (or the current_environment found in the Puppet context).
384
+ # The node's resolved environment is modified if needed.
385
+ #
386
+ def get_configured_environment(node, manifest = nil)
387
+ configured_environment = node.environment || Puppet.lookup(:current_environment)
388
+
389
+ apply_environment = manifest ?
390
+ configured_environment.override_with(:manifest => manifest) :
391
+ configured_environment
392
+
393
+ # Modify the node descriptor to use the special apply_environment.
394
+ # It is based on the actual environment from the node, or the locally
395
+ # configured environment if the node does not specify one.
396
+ # If a manifest file is passed on the command line, it overrides
397
+ # the :manifest setting of the apply_environment.
398
+ node.environment = apply_environment
399
+ apply_environment
400
+ end
401
+
402
+ # Mixes the facts into the node, and mixes in server facts
403
+ def configure_node_facts(node, facts)
404
+ node.merge(facts.values) if facts
405
+ # Add server facts so $server_facts[environment] exists when doing a puppet apply
406
+ node.add_server_facts({})
407
+ end
367
408
  end
@@ -2,102 +2,6 @@ require 'puppet/application'
2
2
 
3
3
  class Puppet::Application::Cert < Puppet::Application
4
4
 
5
- run_mode :master
6
-
7
- attr_accessor :all, :ca, :digest, :signed
8
-
9
- def subcommand
10
- @subcommand
11
- end
12
-
13
- def subcommand=(name)
14
- # Handle the nasty, legacy mapping of "clean" to "destroy".
15
- sub = name.to_sym
16
- @subcommand = (sub == :clean ? :destroy : sub)
17
- end
18
-
19
- option("--clean", "-c") do |arg|
20
- self.subcommand = "destroy"
21
- end
22
-
23
- option("--all", "-a") do |arg|
24
- @all = true
25
- end
26
-
27
- option("--digest DIGEST") do |arg|
28
- @digest = arg
29
- end
30
-
31
- option("--signed", "-s") do |arg|
32
- @signed = true
33
- end
34
-
35
- option("--debug", "-d") do |arg|
36
- options[:debug] = true
37
- set_log_level
38
- end
39
-
40
- option("--list", "-l") do |arg|
41
- self.subcommand = :list
42
- end
43
-
44
- option("--revoke", "-r") do |arg|
45
- self.subcommand = :revoke
46
- end
47
-
48
- option("--generate", "-g") do |arg|
49
- self.subcommand = :generate
50
- end
51
-
52
- option("--sign", "-s") do |arg|
53
- self.subcommand = :sign
54
- end
55
-
56
- option("--print", "-p") do |arg|
57
- self.subcommand = :print
58
- end
59
-
60
- option("--verify", "-v") do |arg|
61
- self.subcommand = :verify
62
- end
63
-
64
- option("--fingerprint", "-f") do |arg|
65
- self.subcommand = :fingerprint
66
- end
67
-
68
- option("--reinventory") do |arg|
69
- self.subcommand = :reinventory
70
- end
71
-
72
- option("--[no-]allow-dns-alt-names") do |value|
73
- options[:allow_dns_alt_names] = value
74
- end
75
-
76
- option("--[no-]allow-authorization-extensions") do |value|
77
- options[:allow_authorization_extensions] = value
78
- end
79
-
80
- option("--verbose", "-v") do |arg|
81
- options[:verbose] = true
82
- set_log_level
83
- end
84
-
85
- option("--human-readable", "-H") do |arg|
86
- options[:format] = :human
87
- end
88
-
89
- option("--machine-readable", "-m") do |arg|
90
- options[:format] = :machine
91
- end
92
-
93
- option("--interactive", "-i") do |arg|
94
- options[:interactive] = true
95
- end
96
-
97
- option("--assume-yes", "-y") do |arg|
98
- options[:yes] = true
99
- end
100
-
101
5
  def summary
102
6
  _("Manage certificates and requests (Disabled)")
103
7
  end
@@ -132,10 +36,10 @@ unless the '--all' option is set.
132
36
  `openssl x509 -noout -text -in certificate.pem`
133
37
 
134
38
  * revoke:
135
- Use `puppetserver ca revoke --cerntname NAME[,NAME...]`
39
+ Use `puppetserver ca revoke --certname NAME[,NAME...]`
136
40
 
137
41
  * sign:
138
- Use `puppetserver ca sign --cerntname NAME[,NAME...]`
42
+ Use `puppetserver ca sign --certname NAME[,NAME...]`
139
43
 
140
44
  * verify:
141
45
  Use `puppet ssl verify [--certname NAME]`
@@ -161,26 +65,12 @@ There are a couple important notes about previously-supported options.
161
65
  HELP
162
66
  end
163
67
 
164
- def main
165
- help
166
- end
167
-
168
68
  def setup
169
69
  deprecate
170
70
  end
171
71
 
172
72
  def parse_options
173
- # handle the bareword subcommand pattern.
174
- result = super
175
- unless self.subcommand then
176
- if sub = self.command_line.args.shift then
177
- self.subcommand = sub
178
- else
179
- puts help
180
- exit
181
- end
182
- end
183
-
184
- result
73
+ puts help
74
+ exit 1
185
75
  end
186
76
  end
@@ -1,4 +1,5 @@
1
1
  require 'puppet/application'
2
+ require 'puppet/configurer'
2
3
  require 'puppet/util/network_device'
3
4
 
4
5
  class Puppet::Application::Device < Puppet::Application
@@ -53,6 +54,10 @@ class Puppet::Application::Device < Puppet::Application
53
54
  options[:detailed_exitcodes] = true
54
55
  end
55
56
 
57
+ option("--libdir LIBDIR") do |arg|
58
+ options[:libdir] = arg
59
+ end
60
+
56
61
  option("--apply MANIFEST") do |arg|
57
62
  options[:apply] = arg.to_s
58
63
  end
@@ -93,10 +98,11 @@ a scheduled task, or a similar tool.
93
98
 
94
99
  USAGE
95
100
  -----
96
- puppet device [-d|--debug] [--detailed-exitcodes] [--deviceconfig <file>]
97
- [-h|--help] [-l|--logdest syslog|<file>|console]
98
- [-v|--verbose] [-w|--waitforcert <seconds>] [-f|--facts]
99
- [-a|--apply <file>] [-r|--resource <type> [name]]
101
+ puppet device [-h|--help] [-v|--verbose] [-d|--debug]
102
+ [-l|--logdest syslog|<file>|console] [--detailed-exitcodes]
103
+ [--deviceconfig <file>] [-w|--waitforcert <seconds>]
104
+ [--libdir <directory>]
105
+ [-a|--apply <file>] [-f|--facts] [-r|--resource <type> [name]]
100
106
  [-t|--target <device>] [--user=<user>] [-V|--version]
101
107
 
102
108
 
@@ -135,9 +141,25 @@ Note that any setting that's valid in the configuration file is also a valid
135
141
  long argument. For example, 'server' is a valid configuration parameter, so
136
142
  you can specify '--server <servername>' as an argument.
137
143
 
138
- * --debug:
144
+ * --help, -h:
145
+ Print this help message
146
+
147
+ * --verbose, -v:
148
+ Turn on verbose reporting.
149
+
150
+ * --debug, -d:
139
151
  Enable full debugging.
140
152
 
153
+ * --logdest, -l:
154
+ Where to send log messages. Choose between 'syslog' (the POSIX syslog
155
+ service), 'console', or the path to a log file. If debugging or verbosity is
156
+ enabled, this defaults to 'console'. Otherwise, it defaults to 'syslog'.
157
+
158
+ A path ending with '.json' will receive structured output in JSON format. The
159
+ log file will not have an ending ']' automatically written to it due to the
160
+ appending nature of logging. It must be appended manually to make the content
161
+ valid JSON.
162
+
141
163
  * --detailed-exitcodes:
142
164
  Provide transaction information via exit codes. If this is enabled, an exit
143
165
  code of '1' means at least one device had a compile failure, an exit code of
@@ -149,18 +171,16 @@ you can specify '--server <servername>' as an argument.
149
171
  Path to the device config file for puppet device.
150
172
  Default: $confdir/device.conf
151
173
 
152
- * --help:
153
- Print this help message
174
+ * --waitforcert, -w:
175
+ This option only matters for targets that do not yet have certificates
176
+ and it is enabled by default, with a value of 120 (seconds). This causes
177
+ +puppet device+ to poll the server every 2 minutes and ask it to sign a
178
+ certificate request. This is useful for the initial setup of a target.
179
+ You can turn off waiting for certificates by specifying a time of 0.
154
180
 
155
- * --logdest:
156
- Where to send log messages. Choose between 'syslog' (the POSIX syslog
157
- service), 'console', or the path to a log file. If debugging or verbosity is
158
- enabled, this defaults to 'console'. Otherwise, it defaults to 'syslog'.
159
-
160
- A path ending with '.json' will receive structured output in JSON format. The
161
- log file will not have an ending ']' automatically written to it due to the
162
- appending nature of logging. It must be appended manually to make the content
163
- valid JSON.
181
+ * --libdir:
182
+ Override the per-device libdir with a local directory. Specifying a libdir also
183
+ disables pluginsync. This is useful for testing.
164
184
 
165
185
  * --apply:
166
186
  Apply a manifest against a remote target. Target must be specified.
@@ -183,16 +203,6 @@ you can specify '--server <servername>' as an argument.
183
203
  * --user:
184
204
  The user to run as.
185
205
 
186
- * --verbose:
187
- Turn on verbose reporting.
188
-
189
- * --waitforcert:
190
- This option only matters for daemons that do not yet have certificates
191
- and it is enabled by default, with a value of 120 (seconds). This causes
192
- +puppet agent+ to connect to the server every 2 minutes and ask it to sign a
193
- certificate request. This is useful for the initial setup of a puppet
194
- client. You can turn off waiting for certificates by specifying a time of 0.
195
-
196
206
 
197
207
  EXAMPLE
198
208
  -------
@@ -205,7 +215,7 @@ Brice Figureau
205
215
 
206
216
  COPYRIGHT
207
217
  ---------
208
- Copyright (c) 2011 Puppet Inc., LLC
218
+ Copyright (c) 2011-2018 Puppet Inc., LLC
209
219
  Licensed under the Apache 2.0 License
210
220
  HELP
211
221
  end
@@ -222,11 +232,12 @@ Licensed under the Apache 2.0 License
222
232
  raise _("missing argument: --target is required when using --apply") if options[:target].nil?
223
233
  raise _("%{file} does not exist, cannot apply") % { file: options[:apply] } unless File.file?(options[:apply])
224
234
  end
235
+ libdir = Puppet[:libdir]
225
236
  vardir = Puppet[:vardir]
226
237
  confdir = Puppet[:confdir]
227
238
  certname = Puppet[:certname]
228
239
 
229
- env = Puppet.lookup(:environments).get(Puppet[:environment])
240
+ env = Puppet::Node::Environment.remote(Puppet[:environment])
230
241
  returns = Puppet.override(:current_environment => env, :loaders => Puppet::Pops::Loaders.new(env)) do
231
242
  # find device list
232
243
  require 'puppet/util/network_device/config'
@@ -251,9 +262,13 @@ Licensed under the Apache 2.0 License
251
262
 
252
263
  # override local $vardir and $certname
253
264
  Puppet[:confdir] = ::File.join(Puppet[:devicedir], device.name)
265
+ Puppet[:libdir] = options[:libdir] || ::File.join(Puppet[:devicedir], device.name, 'lib')
254
266
  Puppet[:vardir] = ::File.join(Puppet[:devicedir], device.name)
255
267
  Puppet[:certname] = device.name
256
268
 
269
+ unless options[:resource] || options[:facts] || options[:apply] || options[:libdir]
270
+ Puppet::Configurer::PluginHandler.new.download_plugins(env)
271
+ end
257
272
  # this init the device singleton, so that the facts terminus
258
273
  # and the various network_device provider can use it
259
274
  Puppet::Util::NetworkDevice.init(device)
@@ -305,17 +320,18 @@ Licensed under the Apache 2.0 License
305
320
  Puppet.settings.use :main, :agent, :ssl
306
321
  # ask for a ssl cert if needed, but at least
307
322
  # setup the ssl system for this device.
308
- setup_host
323
+ setup_host(device.name)
309
324
 
310
325
  require 'puppet/configurer'
311
326
  configurer = Puppet::Configurer.new
312
- configurer.run(:network_device => true, :pluginsync => Puppet::Configurer.should_pluginsync?)
327
+ configurer.run(:network_device => true, :pluginsync => Puppet::Configurer.should_pluginsync? && !options[:libdir])
313
328
  end
314
329
  rescue => detail
315
330
  Puppet.log_exception(detail)
316
331
  # If we rescued an error, then we return 1 as the exit code
317
332
  1
318
333
  ensure
334
+ Puppet[:libdir] = libdir
319
335
  Puppet[:vardir] = vardir
320
336
  Puppet[:confdir] = confdir
321
337
  Puppet[:certname] = certname
@@ -354,8 +370,8 @@ Licensed under the Apache 2.0 License
354
370
  end
355
371
  end
356
372
 
357
- def setup_host
358
- @host = Puppet::SSL::Host.new
373
+ def setup_host(name)
374
+ @host = Puppet::SSL::Host.new(name, true)
359
375
  waitforcert = options[:waitforcert] || (Puppet[:onetime] ? 0 : Puppet[:waitforcert])
360
376
  @host.wait_for_cert(waitforcert)
361
377
  end
@@ -229,9 +229,9 @@ Copyright (c) 2017 Puppet Inc., LLC Licensed under the Apache 2.0 License
229
229
  end
230
230
 
231
231
  def setup
232
-
233
232
  exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
234
233
 
234
+ handle_logdest_arg(Puppet[:logdest])
235
235
  Puppet::Util::Log.newdestination(:console) unless options[:setdest]
236
236
 
237
237
  Signal.trap(:INT) do