bolt 2.29.0 → 2.30.0

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec167b23fc4ceec9d9b3048ae64582a3fcf2baa1eceb8100fb26cc3c6df95cb6
4
- data.tar.gz: 4621d274f8c14f4986dae819755c0db162cd056fbd9412275a0bcffc2169edee
3
+ metadata.gz: c8ca2906e21e39d1da306c9a02ddb970f64955133fcab01574e4138c1e6e154e
4
+ data.tar.gz: 4c875d82bf7ff9d4117440eca9e1276c1b9c2fa842fda4669227ebb0ec56f170
5
5
  SHA512:
6
- metadata.gz: 1af9a8df65a1a95a7404a0b94f74bfeb9086e3a97ba03e1f19a53acbb626757249b69d812f7afe87e2da05a06d698f515b05313018a649621d98269eabfe2f93
7
- data.tar.gz: 24f0b0f56451570d5e97d74ddb66556b48fd8c14a79fd7a0c09f10a4ef1c8590684ccee1675c4dd4126cdbcbc781bad6bf83ba2aa4d8ada0cd13279c15f53876
6
+ metadata.gz: bd8e4327ddfeb4d88fdd1f94ab4233bcf1f0d8ce1390769587197dec11bfa024a16889c5693ec4a4333565cd7553a8c13487b6674ba5427a63f9408961e6a3a7
7
+ data.tar.gz: f2bcbe28ba4c26bc36d3c52ab89a8bafa6a132c930c310a92e48b841d0274389022f2480d3ed397bcc4bcf1f77fb272da82697362d33feccfe05ab0ca203cf6c
data/Puppetfile CHANGED
@@ -31,9 +31,10 @@ mod 'puppetlabs-ruby_plugin_helper', '0.1.0'
31
31
  mod 'puppetlabs-stdlib', '6.3.0'
32
32
 
33
33
  # Plugin modules
34
- mod 'puppetlabs-aws_inventory', '0.5.0'
35
- mod 'puppetlabs-azure_inventory', '0.3.0'
36
- mod 'puppetlabs-gcloud_inventory', '0.1.1'
34
+ mod 'puppetlabs-aws_inventory', '0.5.2'
35
+ mod 'puppetlabs-azure_inventory', '0.4.1'
36
+ mod 'puppetlabs-gcloud_inventory', '0.1.3'
37
+ mod 'puppetlabs-http_request', '0.1.0'
37
38
  mod 'puppetlabs-pkcs7', '0.1.1'
38
39
  mod 'puppetlabs-terraform', '0.5.0'
39
40
  mod 'puppetlabs-vault', '0.3.0'
@@ -66,15 +66,18 @@ module Bolt
66
66
  banner: GUIDE_HELP }
67
67
  when 'module'
68
68
  case action
69
+ when 'add'
70
+ { flags: OPTIONS[:global] + %w[configfile project],
71
+ banner: MODULE_ADD_HELP }
72
+ when 'generate-types'
73
+ { flags: OPTIONS[:global] + OPTIONS[:global_config_setters],
74
+ banner: MODULE_GENERATETYPES_HELP }
69
75
  when 'install'
70
- { flags: OPTIONS[:global] + %w[configfile force project],
76
+ { flags: OPTIONS[:global] + %w[configfile force project resolve],
71
77
  banner: MODULE_INSTALL_HELP }
72
78
  when 'show'
73
79
  { flags: OPTIONS[:global] + OPTIONS[:global_config_setters],
74
80
  banner: MODULE_SHOW_HELP }
75
- when 'generate-types'
76
- { flags: OPTIONS[:global] + OPTIONS[:global_config_setters],
77
- banner: MODULE_GENERATETYPES_HELP }
78
81
  else
79
82
  { flags: OPTIONS[:global],
80
83
  banner: MODULE_HELP }
@@ -184,6 +187,7 @@ module Bolt
184
187
  group Show the list of groups in the inventory
185
188
  guide View guides for Bolt concepts and features
186
189
  inventory Show the list of targets an action would run on
190
+ module Manage Bolt project modules
187
191
  plan Convert, create, show, and run Bolt plans
188
192
  project Create and migrate Bolt projects
189
193
  puppetfile Install and list modules and generate type references
@@ -364,27 +368,34 @@ module Bolt
364
368
  bolt module <action> [options]
365
369
 
366
370
  DESCRIPTION
367
- Install and list modules and generate type references
371
+ Manage Bolt project modules
372
+
373
+ The module command is only supported when a project is configured
374
+ with the 'modules' key.
368
375
 
369
376
  ACTIONS
377
+ add Add a module to the project
370
378
  generate-types Generate type references to register in plans
371
379
  install Install the project's modules
372
380
  show List modules available to the Bolt project
373
381
  HELP
374
382
 
375
- MODULE_INSTALL_HELP = <<~HELP
383
+ MODULE_ADD_HELP = <<~HELP
376
384
  NAME
377
- install
385
+ add
378
386
 
379
387
  USAGE
380
- bolt module install [options]
388
+ bolt module add <module> [options]
381
389
 
382
390
  DESCRIPTION
383
- Install the project's modules.
391
+ Add a module to the project.
384
392
 
385
393
  Module declarations are loaded from the project's configuration
386
394
  file. Bolt will automatically resolve all module dependencies,
387
395
  generate a Puppetfile, and install the modules.
396
+
397
+ The module command is only supported when a project is configured
398
+ with the 'modules' key.
388
399
  HELP
389
400
 
390
401
  MODULE_GENERATETYPES_HELP = <<~HELP
@@ -396,6 +407,24 @@ module Bolt
396
407
 
397
408
  DESCRIPTION
398
409
  Generate type references to register in plans.
410
+
411
+ The module command is only supported when a project is configured
412
+ with the 'modules' key.
413
+ HELP
414
+
415
+ MODULE_INSTALL_HELP = <<~HELP
416
+ NAME
417
+ install
418
+
419
+ USAGE
420
+ bolt module install [options]
421
+
422
+ DESCRIPTION
423
+ Install the project's modules.
424
+
425
+ Module declarations are loaded from the project's configuration
426
+ file. Bolt will automatically resolve all module dependencies,
427
+ generate a Puppetfile, and install the modules.
399
428
  HELP
400
429
 
401
430
  MODULE_SHOW_HELP = <<~HELP
@@ -407,6 +436,9 @@ module Bolt
407
436
 
408
437
  DESCRIPTION
409
438
  List modules available to the Bolt project.
439
+
440
+ The module command is only supported when a project is configured
441
+ with the 'modules' key.
410
442
  HELP
411
443
 
412
444
  PLAN_HELP = <<~HELP
@@ -906,6 +938,13 @@ module Bolt
906
938
  @options[:tmpdir] = tmpdir
907
939
  end
908
940
 
941
+ separator "\nMODULE OPTIONS"
942
+ define('--[no-]resolve',
943
+ 'Use --no-resolve to install modules listed in the Puppetfile without resolving modules configured',
944
+ 'in Bolt project configuration') do |resolve|
945
+ @options[:resolve] = resolve
946
+ end
947
+
909
948
  separator "\nDISPLAY OPTIONS"
910
949
  define('--filter FILTER', 'Filter tasks and plans by a matching substring') do |filter|
911
950
  unless /^[a-z0-9_:]+$/.match(filter)
@@ -97,7 +97,7 @@ module Bolt
97
97
  }
98
98
 
99
99
  with_puppet_settings(puppet_settings) do
100
- Puppet::Pal.in_tmp_environment('bolt_catalog', env_conf) do |pal|
100
+ Puppet::Pal.in_tmp_environment('bolt_catalog', **env_conf) do |pal|
101
101
  Puppet.override(puppet_overrides) do
102
102
  Puppet.lookup(:pal_current_node).trusted_data = target['trusted']
103
103
  pal.with_catalog_compiler do |compiler|
@@ -20,28 +20,31 @@ require 'bolt/logger'
20
20
  require 'bolt/outputter'
21
21
  require 'bolt/puppetdb'
22
22
  require 'bolt/plugin'
23
- require 'bolt/project_migrate'
23
+ require 'bolt/project_migrator'
24
24
  require 'bolt/pal'
25
25
  require 'bolt/target'
26
26
  require 'bolt/version'
27
27
  require 'bolt/secret'
28
+ require 'bolt/module_installer'
28
29
 
29
30
  module Bolt
30
31
  class CLIExit < StandardError; end
31
32
  class CLI
32
- COMMANDS = { 'command' => %w[run],
33
- 'script' => %w[run],
34
- 'task' => %w[show run],
35
- 'plan' => %w[show run convert new],
36
- 'file' => %w[download upload],
37
- 'puppetfile' => %w[install show-modules generate-types],
38
- 'secret' => %w[encrypt decrypt createkeys],
39
- 'inventory' => %w[show],
40
- 'group' => %w[show],
41
- 'project' => %w[init migrate],
42
- 'apply' => %w[],
43
- 'guide' => %w[],
44
- 'module' => %w[install show generate-types] }.freeze
33
+ COMMANDS = {
34
+ 'command' => %w[run],
35
+ 'script' => %w[run],
36
+ 'task' => %w[show run],
37
+ 'plan' => %w[show run convert new],
38
+ 'file' => %w[download upload],
39
+ 'puppetfile' => %w[install show-modules generate-types],
40
+ 'secret' => %w[encrypt decrypt createkeys],
41
+ 'inventory' => %w[show],
42
+ 'group' => %w[show],
43
+ 'project' => %w[init migrate],
44
+ 'module' => %w[add generate-types install show],
45
+ 'apply' => %w[],
46
+ 'guide' => %w[]
47
+ }.freeze
45
48
 
46
49
  attr_reader :config, :options
47
50
 
@@ -99,6 +102,10 @@ module Bolt
99
102
  # This part aims to handle both `bolt <mode> --help` and `bolt help <mode>`.
100
103
  remaining = handle_parser_errors { parser.permute(@argv) } unless @argv.empty?
101
104
  if @argv.empty? || help?(remaining)
105
+ # If the subcommand is not enabled, display the default
106
+ # help text
107
+ options[:subcommand] = nil unless COMMANDS.include?(options[:subcommand])
108
+
102
109
  # Update the parser for the subcommand (or lack thereof)
103
110
  parser.update
104
111
  puts parser.help
@@ -189,6 +196,10 @@ module Bolt
189
196
 
190
197
  warn_inventory_overrides_cli(options)
191
198
 
199
+ # Assert whether the puppetfile/module commands are available depending
200
+ # on whether 'modules' is configured.
201
+ assert_puppetfile_or_module_command(config.project.modules)
202
+
192
203
  options
193
204
  rescue Bolt::Error => e
194
205
  outputter.fatal_error(e)
@@ -216,14 +227,10 @@ module Bolt
216
227
  end
217
228
 
218
229
  def validate(options)
219
- # Disables the 'module' subcommand unless the module feature flag is set.
220
- commands = COMMANDS.dup
221
- commands.delete('module') unless ENV['BOLT_MODULE_FEATURE']
222
-
223
- unless commands.include?(options[:subcommand])
230
+ unless COMMANDS.include?(options[:subcommand])
224
231
  raise Bolt::CLIError,
225
232
  "Expected subcommand '#{options[:subcommand]}' to be one of " \
226
- "#{commands.keys.join(', ')}"
233
+ "#{COMMANDS.keys.join(', ')}"
227
234
  end
228
235
 
229
236
  actions = COMMANDS[options[:subcommand]]
@@ -240,12 +247,6 @@ module Bolt
240
247
  end
241
248
  end
242
249
 
243
- if options[:subcommand] != 'file' && options[:subcommand] != 'script' &&
244
- !options[:leftovers].empty?
245
- raise Bolt::CLIError,
246
- "Unknown argument(s) #{options[:leftovers].join(', ')}"
247
- end
248
-
249
250
  if %w[task plan].include?(options[:subcommand]) && options[:action] == 'run'
250
251
  if options[:object].nil?
251
252
  raise Bolt::CLIError, "Must specify a #{options[:subcommand]} to run"
@@ -257,23 +258,6 @@ module Bolt
257
258
  end
258
259
  end
259
260
 
260
- if options[:boltdir] && options[:configfile]
261
- raise Bolt::CLIError, "Only one of '--boltdir', '--project', or '--configfile' may be specified"
262
- end
263
-
264
- if options[:noop] &&
265
- !(options[:subcommand] == 'task' && options[:action] == 'run') && options[:subcommand] != 'apply'
266
- raise Bolt::CLIError,
267
- "Option '--noop' may only be specified when running a task or applying manifest code"
268
- end
269
-
270
- if options[:env_vars]
271
- unless %w[command script].include?(options[:subcommand]) && options[:action] == 'run'
272
- raise Bolt::CLIError,
273
- "Option '--env-var' may only be specified when running a command or script"
274
- end
275
- end
276
-
277
261
  if options[:subcommand] == 'apply' && (options[:object] && options[:code])
278
262
  raise Bolt::CLIError, "--execute is unsupported when specifying a manifest file"
279
263
  end
@@ -296,6 +280,38 @@ module Bolt
296
280
  raise Bolt::CLIError, "Must specify a plan name."
297
281
  end
298
282
 
283
+ if options[:subcommand] == 'module' && options[:action] == 'add' && !options[:object]
284
+ raise Bolt::CLIError, "Must specify a module name."
285
+ end
286
+
287
+ if options[:subcommand] == 'module' && options[:action] == 'install' && options[:object]
288
+ raise Bolt::CLIError, "Invalid argument '#{options[:object]}'. To add a new module to "\
289
+ "the project, run 'bolt module add #{options[:object]}'."
290
+ end
291
+
292
+ if options[:subcommand] != 'file' && options[:subcommand] != 'script' &&
293
+ !options[:leftovers].empty?
294
+ raise Bolt::CLIError,
295
+ "Unknown argument(s) #{options[:leftovers].join(', ')}"
296
+ end
297
+
298
+ if options[:boltdir] && options[:configfile]
299
+ raise Bolt::CLIError, "Only one of '--boltdir', '--project', or '--configfile' may be specified"
300
+ end
301
+
302
+ if options[:noop] &&
303
+ !(options[:subcommand] == 'task' && options[:action] == 'run') && options[:subcommand] != 'apply'
304
+ raise Bolt::CLIError,
305
+ "Option '--noop' may only be specified when running a task or applying manifest code"
306
+ end
307
+
308
+ if options[:env_vars]
309
+ unless %w[command script].include?(options[:subcommand]) && options[:action] == 'run'
310
+ raise Bolt::CLIError,
311
+ "Option '--env-var' may only be specified when running a command or script"
312
+ end
313
+ end
314
+
299
315
  if options.key?(:debug) && options.key?(:log)
300
316
  raise Bolt::CLIError, "Only one of '--debug' or '--log-level' may be specified"
301
317
  end
@@ -389,7 +405,7 @@ module Bolt
389
405
  inventory_version: inventory.version)
390
406
  end
391
407
 
392
- analytics.screen_view(screen, screen_view_fields)
408
+ analytics.screen_view(screen, **screen_view_fields)
393
409
 
394
410
  case options[:action]
395
411
  when 'show'
@@ -444,9 +460,7 @@ module Bolt
444
460
  when 'init'
445
461
  code = initialize_project
446
462
  when 'migrate'
447
- inv = config.inventoryfile
448
- path = config.project.path
449
- code = Bolt::ProjectMigrate.new(path, outputter, inv).migrate_project
463
+ code = Bolt::ProjectMigrator.new(config, outputter).migrate
450
464
  end
451
465
  when 'plan'
452
466
  case options[:action]
@@ -457,8 +471,10 @@ module Bolt
457
471
  end
458
472
  when 'module'
459
473
  case options[:action]
474
+ when 'add'
475
+ code = add_project_module(options[:object], config.project)
460
476
  when 'install'
461
- code = install_project_modules
477
+ code = install_project_modules(config.project, options[:force], options[:resolve])
462
478
  when 'generate-types'
463
479
  code = generate_types
464
480
  end
@@ -467,7 +483,11 @@ module Bolt
467
483
  when 'generate-types'
468
484
  code = generate_types
469
485
  when 'install'
470
- code = install_puppetfile(config.puppetfile_config, config.puppetfile, config.modulepath.first)
486
+ code = install_puppetfile(
487
+ config.puppetfile_config,
488
+ config.puppetfile,
489
+ config.modulepath.first
490
+ )
471
491
  end
472
492
  when 'secret'
473
493
  code = Bolt::Secret.execute(plugins, outputter, options)
@@ -842,7 +862,8 @@ module Bolt
842
862
  "project with modules."
843
863
  end
844
864
 
845
- install_modules(puppetfile, {}, moduledir, options[:modules])
865
+ installer = Bolt::ModuleInstaller.new(outputter, pal)
866
+ installer.install(options[:modules], puppetfile, moduledir)
846
867
  end
847
868
 
848
869
  # If either bolt.yaml or bolt-project.yaml exist, the user has already
@@ -863,83 +884,83 @@ module Bolt
863
884
 
864
885
  # Installs modules declared in the project configuration file.
865
886
  #
866
- def install_project_modules
867
- if config.project.modules.nil?
868
- outputter.print_message "Project configuration file '#{config.project.project_file}' "\
869
- "does not specify any module dependencies. Nothing to do."
887
+ def install_project_modules(project, force, resolve)
888
+ assert_project_file(project)
889
+
890
+ unless project.modules
891
+ outputter.print_message "Project configuration file #{project.project_file} does not "\
892
+ "specify any module dependencies. Nothing to do."
870
893
  return 0
871
894
  end
872
895
 
873
- install_modules(
874
- config.puppetfile,
875
- config.puppetfile_config,
876
- config.project.path + '.modules',
877
- config.project.modules
878
- )
896
+ installer = Bolt::ModuleInstaller.new(outputter, pal)
897
+
898
+ ok = installer.install(project.modules,
899
+ project.puppetfile,
900
+ project.managed_moduledir,
901
+ force: force,
902
+ resolve: resolve)
903
+ ok ? 0 : 1
879
904
  end
880
905
 
881
- # Installs modules declared in the project configuration file.
906
+ # Adds a single module to the project.
882
907
  #
883
- def install_modules(puppetfile_path, config, moduledir, modules)
884
- require 'bolt/puppetfile'
885
- require 'bolt/puppetfile/installer'
886
-
887
- puppetfile = Bolt::Puppetfile.new(modules)
888
-
889
- # If the Puppetfile exists, check if it includes specs for each declared
890
- # module, erroring if there are any missing. Otherwise, resolve the
891
- # module dependencies and write a new Puppetfile. Users can forcibly
892
- # overwrite an existing Puppetfile with the '--force' option.
893
- if puppetfile_path.exist? && !options[:force]
894
- outputter.print_message "Parsing existing Puppetfile at #{puppetfile_path}"
895
- existing = Bolt::Puppetfile.parse(puppetfile_path)
896
-
897
- unless existing.modules.superset? puppetfile.modules
898
- missing_modules = puppetfile.modules - existing.modules
899
-
900
- message = <<~MESSAGE.chomp
901
- Puppetfile #{puppetfile_path} is missing specifications for the following
902
- module declarations:
903
-
904
- #{missing_modules.map(&:to_hash).to_yaml.lines.drop(1).join.chomp}
905
-
906
- This may not be a Puppetfile managed by Bolt. To forcibly overwrite the
907
- Puppetfile, run 'bolt module install --force'.
908
- MESSAGE
909
-
910
- raise Bolt::Error.new(message, 'bolt/missing-module-specs')
911
- end
912
- else
913
- outputter.print_message "Resolving module dependencies, this may take a moment"
914
- puppetfile.resolve
915
- outputter.print_message "Writing Puppetfile at #{puppetfile_path}"
916
- puppetfile.write(puppetfile_path, force: true)
917
- end
918
-
919
- outputter.print_message "Syncing modules from #{puppetfile_path} to #{moduledir}"
920
- ok = Bolt::Puppetfile::Installer.new(config).install(puppetfile_path, moduledir)
908
+ def add_project_module(name, project)
909
+ assert_project_file(project)
921
910
 
922
- # Automatically generate types after installing modules.
923
- pal.generate_types
911
+ modules = project.modules || []
912
+ installer = Bolt::ModuleInstaller.new(outputter, pal)
924
913
 
925
- outputter.print_puppetfile_result(ok, puppetfile_path, moduledir)
914
+ ok = installer.add(name,
915
+ modules,
916
+ project.puppetfile,
917
+ project.managed_moduledir,
918
+ project.project_file)
926
919
  ok ? 0 : 1
927
920
  end
928
921
 
929
- # Loads a Puppetfile and installs its modules.
922
+ # Asserts that there is a project configuration file.
930
923
  #
931
- def install_puppetfile(config, puppetfile, moduledir)
932
- require 'bolt/puppetfile/installer'
933
-
934
- ok = Bolt::Puppetfile::Installer.new(config).install(puppetfile, moduledir)
924
+ def assert_project_file(project)
925
+ unless project.project_file?
926
+ msg = if project.config_file.exist?
927
+ "Detected Bolt configuration file #{project.config_file}, unable to install "\
928
+ "modules. To update to a project configuration file, run 'bolt project migrate'."
929
+ else
930
+ "Could not find project configuration file #{project.project_file}, unable "\
931
+ "to install modules. To create a Bolt project, run 'bolt project init'."
932
+ end
935
933
 
936
- # Automatically generate types after installing modules.
937
- pal.generate_types
934
+ raise Bolt::Error.new(msg, 'bolt/missing-project-config-error')
935
+ end
936
+ end
938
937
 
939
- outputter.print_puppetfile_result(ok, puppetfile, moduledir)
938
+ # Loads a Puppetfile and installs its modules.
939
+ #
940
+ def install_puppetfile(config, puppetfile, moduledir)
941
+ installer = Bolt::ModuleInstaller.new(outputter, pal)
942
+ ok = installer.install_puppetfile(puppetfile, moduledir, config)
940
943
  ok ? 0 : 1
941
944
  end
942
945
 
946
+ # Raises an error if the 'puppetfile install' command is deprecated due to
947
+ # modules being configured.
948
+ #
949
+ def assert_puppetfile_or_module_command(modules)
950
+ if modules && options[:subcommand] == 'puppetfile'
951
+ raise Bolt::CLIError,
952
+ "Unable to use command 'bolt puppetfile #{options[:action]}' when "\
953
+ "'modules' is configured in bolt-project.yaml. Use the 'module' command "\
954
+ "instead. For a list of available actions for the 'module' command, run "\
955
+ "'bolt module --help'."
956
+ elsif modules.nil? && options[:subcommand] == 'module'
957
+ raise Bolt::CLIError,
958
+ "Unable to use command 'bolt module #{options[:action]}'. To use "\
959
+ "this command, update your project configuration to manage module "\
960
+ "dependencies."
961
+ end
962
+ end
963
+
943
964
  def pal
944
965
  @pal ||= Bolt::PAL.new(config.modulepath,
945
966
  config.hiera_config,