bolt 2.42.0 → 2.44.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.

Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Puppetfile +12 -12
  3. data/bolt-modules/boltlib/lib/puppet/functions/parallelize.rb +6 -8
  4. data/lib/bolt/analytics.rb +3 -2
  5. data/lib/bolt/applicator.rb +11 -1
  6. data/lib/bolt/bolt_option_parser.rb +20 -13
  7. data/lib/bolt/catalog.rb +10 -29
  8. data/lib/bolt/cli.rb +22 -32
  9. data/lib/bolt/config.rb +84 -82
  10. data/lib/bolt/config/options.rb +68 -0
  11. data/lib/bolt/config/transport/options.rb +7 -0
  12. data/lib/bolt/config/transport/orch.rb +1 -0
  13. data/lib/bolt/executor.rb +15 -5
  14. data/lib/bolt/inventory.rb +1 -1
  15. data/lib/bolt/inventory/group.rb +7 -4
  16. data/lib/bolt/logger.rb +114 -10
  17. data/lib/bolt/module_installer.rb +4 -2
  18. data/lib/bolt/module_installer/resolver.rb +59 -14
  19. data/lib/bolt/module_installer/specs/forge_spec.rb +8 -2
  20. data/lib/bolt/module_installer/specs/git_spec.rb +17 -2
  21. data/lib/bolt/outputter/human.rb +8 -4
  22. data/lib/bolt/outputter/rainbow.rb +3 -3
  23. data/lib/bolt/pal.rb +93 -14
  24. data/lib/bolt/pal/yaml_plan.rb +8 -2
  25. data/lib/bolt/pal/yaml_plan/evaluator.rb +2 -2
  26. data/lib/bolt/pal/yaml_plan/transpiler.rb +1 -0
  27. data/lib/bolt/plugin.rb +2 -2
  28. data/lib/bolt/plugin/cache.rb +7 -7
  29. data/lib/bolt/plugin/module.rb +1 -1
  30. data/lib/bolt/plugin/puppet_connect_data.rb +35 -0
  31. data/lib/bolt/plugin/puppetdb.rb +1 -1
  32. data/lib/bolt/project.rb +56 -43
  33. data/lib/bolt/rerun.rb +1 -1
  34. data/lib/bolt/shell/bash.rb +1 -1
  35. data/lib/bolt/shell/bash/tmpdir.rb +4 -1
  36. data/lib/bolt/shell/powershell.rb +2 -2
  37. data/lib/bolt/task.rb +1 -1
  38. data/lib/bolt/transport/docker/connection.rb +2 -2
  39. data/lib/bolt/transport/local.rb +1 -1
  40. data/lib/bolt/transport/orch/connection.rb +1 -1
  41. data/lib/bolt/transport/ssh.rb +1 -2
  42. data/lib/bolt/transport/ssh/connection.rb +1 -1
  43. data/lib/bolt/validator.rb +2 -2
  44. data/lib/bolt/version.rb +1 -1
  45. data/lib/bolt_server/config.rb +1 -1
  46. data/lib/bolt_server/transport_app.rb +2 -1
  47. data/libexec/bolt_catalog +1 -1
  48. metadata +9 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d520aad8f699a4a52849ac189a6368b799238996a0c4dae22e75f2abfbe43eff
4
- data.tar.gz: befcf8835708c4ec4605e560dfd060680a6d680b7614bfd3d4d4baba7fb7cfa5
3
+ metadata.gz: aa7f2db70ebfda5de9128554d289d3506ad0c922dac4042e80e29ad691b04447
4
+ data.tar.gz: b0eedc91174b14a594352d3033a27c13f4f29dbd038679345568e39bea486bc4
5
5
  SHA512:
6
- metadata.gz: 0f25f959178fe587c518723cdc1dffd7bd420ea1d943ff1dcfda410cffd0ad592d3cd5714f5d4707dc9a4aa6fec0eb3103382a0266bf56f0625c2c06bc325f98
7
- data.tar.gz: 7b05c93e0f507429bd5c43d5a0d0ed51f42d8ac1c0621c1c125ac1905a193a09e6802bb898f90650f7b95d8b0a2c5c513adbf93b3626d109936a447dcfaaf3dd
6
+ metadata.gz: 1d5620a57dbf4ba82778704296116f53b162a469557162f766c208a5ca5d01e52fbdb219c8e9e965823dca7224dfd1dec507cb432d0d64fa29604fc117a1930f
7
+ data.tar.gz: 0fdf98e91e30c49960caf5b67bca32d6698c3df18ce1d75db98831cfc0694ac1ba444c08691e809ba3ecca76d702b16e46154ed5fc65a59db432f27355bf57a0
data/Puppetfile CHANGED
@@ -6,8 +6,8 @@ moduledir File.join(File.dirname(__FILE__), 'modules')
6
6
 
7
7
  # Core modules used by 'apply'
8
8
  mod 'puppetlabs-service', '1.4.0'
9
- mod 'puppetlabs-puppet_agent', '4.3.0'
10
- mod 'puppetlabs-facts', '1.3.0'
9
+ mod 'puppetlabs-puppet_agent', '4.4.0'
10
+ mod 'puppetlabs-facts', '1.4.0'
11
11
 
12
12
  # Core types and providers for Puppet 6
13
13
  mod 'puppetlabs-augeas_core', '1.1.1'
@@ -24,21 +24,21 @@ mod 'puppetlabs-zone_core', '1.0.3'
24
24
  # Useful additional modules
25
25
  mod 'puppetlabs-package', '1.4.0'
26
26
  mod 'puppetlabs-puppet_conf', '0.8.0'
27
- mod 'puppetlabs-python_task_helper', '0.4.3'
28
- mod 'puppetlabs-reboot', '3.1.0'
29
- mod 'puppetlabs-ruby_task_helper', '0.5.1'
30
- mod 'puppetlabs-ruby_plugin_helper', '0.1.0'
27
+ mod 'puppetlabs-python_task_helper', '0.5.0'
28
+ mod 'puppetlabs-reboot', '3.2.0'
29
+ mod 'puppetlabs-ruby_task_helper', '0.6.0'
30
+ mod 'puppetlabs-ruby_plugin_helper', '0.2.0'
31
31
  mod 'puppetlabs-stdlib', '6.5.0'
32
32
 
33
33
  # Plugin modules
34
- mod 'puppetlabs-aws_inventory', '0.5.2'
35
- mod 'puppetlabs-azure_inventory', '0.4.1'
36
- mod 'puppetlabs-gcloud_inventory', '0.1.3'
34
+ mod 'puppetlabs-aws_inventory', '0.6.0'
35
+ mod 'puppetlabs-azure_inventory', '0.5.0'
36
+ mod 'puppetlabs-gcloud_inventory', '0.2.0'
37
37
  mod 'puppetlabs-http_request', '0.2.1'
38
38
  mod 'puppetlabs-pkcs7', '0.1.1'
39
- mod 'puppetlabs-secure_env_vars', '0.1.0'
40
- mod 'puppetlabs-terraform', '0.5.0'
41
- mod 'puppetlabs-vault', '0.3.0'
39
+ mod 'puppetlabs-secure_env_vars', '0.2.0'
40
+ mod 'puppetlabs-terraform', '0.6.1'
41
+ mod 'puppetlabs-vault', '0.4.0'
42
42
  mod 'puppetlabs-yaml', '0.2.0'
43
43
 
44
44
  # If we don't list these modules explicitly, r10k will purge them
@@ -12,14 +12,12 @@ Puppet::Functions.create_function(:parallelize, Puppet::Functions::InternalFunct
12
12
  # @param data The array to apply the block to.
13
13
  # @return [Array] An array of PlanResult objects. Each input from the input
14
14
  # array returns a corresponding PlanResult object.
15
- # @example Execute two tasks on multiple targets. Once the task finishes on one
16
- # target, that target can move to the next step without waiting for the task
17
- # to finish on the second target.
18
- # $targets = get_targets(["host1", "host2"])
19
- # $result = parallelize ($targets) |$t| {
20
- # run_task('a', $t)
21
- # run_task('b', $t)
22
- # }
15
+ # @example Execute two tasks on two targets.
16
+ # $targets = get_targets(["host1", "host2"])
17
+ # $result = parallelize ($targets) |$t| {
18
+ # run_task('a', $t)
19
+ # run_task('b', $t)
20
+ # }
23
21
  dispatch :parallelize do
24
22
  scope_param
25
23
  param 'Array[Any]', :data
@@ -78,7 +78,7 @@ module Bolt
78
78
  Bolt::Util.read_optional_yaml_hash(filename, 'analytics')
79
79
  else
80
80
  unless ENV['BOLT_DISABLE_ANALYTICS']
81
- Bolt::Logger.warn_once('analytics_opt_out', <<~ANALYTICS)
81
+ msg = <<~ANALYTICS
82
82
  Bolt collects data about how you use it. You can opt out of providing this data.
83
83
 
84
84
  To disable analytics data collection, add this line to ~/.puppetlabs/etc/bolt/analytics.yaml :
@@ -86,7 +86,8 @@ module Bolt
86
86
 
87
87
  Read more about what data Bolt collects and why here:
88
88
  https://puppet.com/docs/bolt/latest/bolt_installing.html#analytics-data-collection
89
- ANALYTICS
89
+ ANALYTICS
90
+ Bolt::Logger.warn_once('analytics_opt_out', msg)
90
91
  end
91
92
 
92
93
  {}
@@ -125,7 +125,16 @@ module Bolt
125
125
  @logger.send(bolt_level, "#{target.name}: #{message}")
126
126
  end
127
127
  end
128
- raise ApplyError.new(target.name, result['message']) unless stat.success?
128
+
129
+ unless stat.success?
130
+ message = if @apply_settings['trace'] && result['backtrace']
131
+ ([result['message']] + result['backtrace']).join("\n ")
132
+ else
133
+ result['message']
134
+ end
135
+ raise ApplyError.new(target.name, message)
136
+ end
137
+
129
138
  result
130
139
  end
131
140
 
@@ -236,6 +245,7 @@ module Bolt
236
245
  else
237
246
  Bolt::ApplyError.new(batch_target, future.reason.message)
238
247
  end
248
+
239
249
  result = Bolt::ApplyResult.new(batch_target, error: error.to_h)
240
250
  @executor.publish_event(type: :node_result, result: result)
241
251
  result
@@ -760,13 +760,10 @@ module Bolt
760
760
  bolt task show canary
761
761
  HELP
762
762
 
763
- attr_reader :deprecations
764
-
765
763
  def initialize(options)
766
764
  super()
767
765
 
768
766
  @options = options
769
- @deprecations = []
770
767
 
771
768
  separator "\nINVENTORY OPTIONS"
772
769
  define('-t', '--targets TARGETS',
@@ -796,9 +793,11 @@ module Bolt
796
793
  end
797
794
  define('--description DESCRIPTION',
798
795
  'Deprecated. Description to use for the job') do |description|
799
- msg = "Command line option '--description' is deprecated, and will be "\
796
+ Bolt::Logger.deprecate(
797
+ "description_cli_option",
798
+ "Command line option '--description' is deprecated, and will be "\
800
799
  "removed in Bolt 3.0."
801
- @deprecations << { type: 'Using --description', msg: msg }
800
+ )
802
801
  @options[:description] = description
803
802
  end
804
803
  define('--params PARAMETERS',
@@ -881,8 +880,10 @@ module Bolt
881
880
  define('--boltdir PATH',
882
881
  'Deprecated. Specify what project to load config from (default:',
883
882
  'autodiscovered from current working dir)') do |path|
884
- msg = "Command line option '--boltdir' is deprecated, use '--project' instead."
885
- @deprecations << { type: 'Using --boltdir', msg: msg }
883
+ Bolt::Logger.deprecate(
884
+ "boltdir_cli_option",
885
+ "Command line option '--boltdir' is deprecated, use '--project' instead."
886
+ )
886
887
  @options[:boltdir] = path
887
888
  end
888
889
  define('--project PATH',
@@ -893,10 +894,12 @@ module Bolt
893
894
  'Deprecated. Specify where to load config from (default:',
894
895
  '~/.puppetlabs/bolt/bolt.yaml). Directory containing bolt.yaml will be',
895
896
  'used as the project directory.') do |path|
896
- msg = "Command line option '--configfile' is deprecated, and " \
897
+ Bolt::Logger.deprecate(
898
+ "configfile_cli_option",
899
+ "Command line option '--configfile' is deprecated, and " \
897
900
  "will be removed in Bolt 3.0. Use '--project' and provide the "\
898
901
  "directory path instead."
899
- @deprecations << { type: 'Using --configfile', msg: msg }
902
+ )
900
903
  @options[:configfile] = path
901
904
  end
902
905
  define('--hiera-config PATH',
@@ -915,10 +918,12 @@ module Bolt
915
918
  ' (default: ~/.puppetlabs/bolt/Puppetfile)',
916
919
  'Modules are installed in the current project.') do |path|
917
920
  command = Bolt::Util.powershell? ? 'Update-BoltProject' : 'bolt project migrate'
918
- msg = "Command line option '--puppetfile' is deprecated, and will be removed "\
921
+ Bolt::Logger.deprecate(
922
+ "puppetfile_cli_option",
923
+ "Command line option '--puppetfile' is deprecated, and will be removed "\
919
924
  "in Bolt 3.0. You can migrate to using the new module management "\
920
925
  "workflow using '#{command}'."
921
- @deprecations << { type: 'Using --puppetfile', msg: msg }
926
+ )
922
927
  @options[:puppetfile_path] = File.expand_path(path)
923
928
  end
924
929
  define('--[no-]save-rerun', 'Whether to update the rerun file after this command.') do |save|
@@ -1017,8 +1022,10 @@ module Bolt
1017
1022
  @options[:debug] = true
1018
1023
  # We don't actually set '--log-level debug' here, but once the options are evaluated by
1019
1024
  # the config class the end result is the same.
1020
- msg = "Command line option '--debug' is deprecated, set '--log-level debug' instead."
1021
- @deprecations << { type: 'Using --debug instead of --log-level debug', msg: msg }
1025
+ Bolt::Logger.deprecate(
1026
+ "debug_cli_option",
1027
+ "Command line option '--debug' is deprecated, set '--log-level debug' instead."
1028
+ )
1022
1029
  end
1023
1030
  define('--log-level LEVEL',
1024
1031
  "Set the log level for the console. Available options are",
@@ -76,31 +76,27 @@ module Bolt
76
76
  # is the only way to log a message that will make it back to Bolt
77
77
  # to be printed.
78
78
  target = request['target']
79
- plan_vars = shadow_vars('plan', request['plan_vars'], target['facts'])
80
- target_vars = shadow_vars('target', target['variables'], target['facts'])
81
79
 
82
- # Merge plan vars with target vars, while maintaining the order of the plan
83
- # vars. It's critical that the order of plan vars is not changed, as Puppet
84
- # will deserialize the variables in the order they appear. Variables may
85
- # contain local references to variables that appear earlier in a plan. If
86
- # these variables are moved before the variable they reference, Puppet will
87
- # be unable to deserialize the data and raise an error.
88
- topscope_vars = target_vars.reject { |k, _v| plan_vars.key?(k) }.merge(plan_vars)
80
+ variables = {
81
+ variables: request['plan_vars'],
82
+ target_variables: target['variables']
83
+ }
89
84
 
90
- env_conf = { modulepath: request['modulepath'],
91
- facts: target['facts'],
92
- variables: topscope_vars }
85
+ env_conf = {
86
+ modulepath: request['modulepath'],
87
+ facts: target['facts']
88
+ }
93
89
 
94
90
  puppet_settings = {
95
91
  node_name_value: target['name'],
96
- hiera_config: request['hiera_config']
92
+ hiera_config: request['hiera_config']
97
93
  }
98
94
 
99
95
  with_puppet_settings(puppet_settings) do
100
96
  Puppet::Pal.in_tmp_environment('bolt_catalog', **env_conf) do |pal|
101
97
  Puppet.override(puppet_overrides) do
102
98
  Puppet.lookup(:pal_current_node).trusted_data = target['trusted']
103
- pal.with_catalog_compiler do |compiler|
99
+ pal.with_catalog_compiler(**variables) do |compiler|
104
100
  options = request['puppet_config'] || {}
105
101
  # Configure language strictness in the CatalogCompiler. We want Bolt to be able
106
102
  # to compile most Puppet 4+ manifests, so we default to allowing deprecated functions.
@@ -119,21 +115,6 @@ module Bolt
119
115
  end
120
116
  end
121
117
 
122
- # Warn and remove variables that will be shadowed by facts of the same
123
- # name, which are set in scope earlier.
124
- def shadow_vars(type, vars, facts)
125
- collisions, valid = vars.partition do |k, _|
126
- facts.include?(k)
127
- end
128
- if collisions.any?
129
- names = collisions.map { |k, _| "$#{k}" }.join(', ')
130
- plural = collisions.length == 1 ? '' : 's'
131
- Puppet.warning("#{type.capitalize} variable#{plural} #{names} will be overridden by fact#{plural} " \
132
- "of the same name in the apply block")
133
- end
134
- valid.to_h
135
- end
136
-
137
118
  def build_program(code)
138
119
  ast = Puppet::Pops::Serialization::FromDataConverter.convert(code)
139
120
 
@@ -147,10 +147,6 @@ module Bolt
147
147
  end
148
148
 
149
149
  validate(options)
150
-
151
- # Deprecation warnings can't be issued until after config is loaded, so
152
- # store them for later.
153
- @parser_deprecations = parser.deprecations
154
150
  rescue Bolt::Error => e
155
151
  fatal_error(e)
156
152
  raise e
@@ -185,20 +181,16 @@ module Bolt
185
181
 
186
182
  # Completes the setup process by configuring Bolt and log messages
187
183
  def finalize_setup
188
- Bolt::Logger.configure(config.log, config.color)
184
+ Bolt::Logger.configure(config.log, config.color, config.disable_warnings)
189
185
  Bolt::Logger.analytics = analytics
186
+ Bolt::Logger.flush_queue
190
187
 
191
188
  # Logger must be configured before checking path case and project file, otherwise logs will not display
192
189
  config.check_path_case('modulepath', config.modulepath)
193
190
  config.project.check_deprecated_file
194
191
 
195
- # Log messages created during parser and config initialization
196
- config.logs.each { |log| @logger.send(log.keys[0], log.values[0]) }
197
- @parser_deprecations.each { |dep| Bolt::Logger.deprecation_warning(dep[:type], dep[:msg]) }
198
- config.deprecations.each { |dep| Bolt::Logger.deprecation_warning(dep[:type], dep[:msg]) }
199
-
200
- if options[:clear_cache] && File.exist?(config.project.cache_file)
201
- FileUtils.rm(config.project.cache_file)
192
+ if options[:clear_cache] && File.exist?(config.project.plugin_cache_file)
193
+ FileUtils.rm(config.project.plugin_cache_file)
202
194
  end
203
195
 
204
196
  warn_inventory_overrides_cli(options)
@@ -220,7 +212,7 @@ module Bolt
220
212
 
221
213
  msg = "Detected PowerShell 2 on controller. PowerShell 2 is deprecated and "\
222
214
  "support will be removed in Bolt 3.0."
223
- Bolt::Logger.deprecation_warning("PowerShell 2 controller", msg)
215
+ Bolt::Logger.deprecate("powershell_2_controller", msg)
224
216
  end
225
217
  end
226
218
 
@@ -376,7 +368,10 @@ module Bolt
376
368
  conflicting_options = Set.new(opts.keys.map(&:to_s)).intersection(inventory_cli_opts)
377
369
 
378
370
  if inventory_source && conflicting_options.any?
379
- @logger.warn("CLI arguments #{conflicting_options.to_a} may be overridden by Inventory: #{inventory_source}")
371
+ Bolt::Logger.warn(
372
+ "cli_overrides",
373
+ "CLI arguments #{conflicting_options.to_a} may be overridden by Inventory: #{inventory_source}"
374
+ )
380
375
  end
381
376
  end
382
377
 
@@ -541,15 +536,12 @@ module Bolt
541
536
  validate_file('script', script)
542
537
  executor.run_script(targets, script, options[:leftovers], executor_opts)
543
538
  when 'task'
544
- r = outputter.spin do
545
- pal.run_task(options[:object],
546
- targets,
547
- options[:task_options],
548
- executor,
549
- inventory,
550
- options[:description])
551
- end
552
- r
539
+ pal.run_task(options[:object],
540
+ targets,
541
+ options[:task_options],
542
+ executor,
543
+ inventory,
544
+ options[:description])
553
545
  when 'file'
554
546
  src = options[:object]
555
547
  dest = options[:leftovers].first
@@ -610,7 +602,7 @@ module Bolt
610
602
  end
611
603
 
612
604
  def list_plans
613
- plans = filter_content(pal.list_plans(filter_content: true), options[:filter])
605
+ plans = filter_content(pal.list_plans_with_cache(filter_content: true), options[:filter])
614
606
  outputter.print_plans(plans, pal.user_modulepath)
615
607
  end
616
608
 
@@ -662,7 +654,7 @@ module Bolt
662
654
  if node_param && target_param
663
655
  msg = "Plan parameters include both 'nodes' and 'targets' with type 'TargetSpec', " \
664
656
  "neither will populated with the value for --nodes or --targets."
665
- @logger.warn(msg)
657
+ Bolt::Logger.warn("nodes_targets_parameters", msg)
666
658
  elsif node_param
667
659
  plan_arguments['nodes'] = nodes.join(',')
668
660
  elsif target_param
@@ -684,9 +676,7 @@ module Bolt
684
676
 
685
677
  executor.subscribe(log_outputter)
686
678
  executor.start_plan(plan_context)
687
- result = outputter.spin do
688
- pal.run_plan(plan_name, plan_arguments, executor, inventory, puppetdb_client)
689
- end
679
+ result = pal.run_plan(plan_name, plan_arguments, executor, inventory, puppetdb_client)
690
680
 
691
681
  # If a non-bolt exception bubbles up the plan won't get finished
692
682
  executor.finish_plan(result)
@@ -709,7 +699,7 @@ module Bolt
709
699
  "about defining and declaring classes and types in the Puppet documentation at "\
710
700
  "https://puppet.com/docs/puppet/latest/lang_classes.html and "\
711
701
  "https://puppet.com/docs/puppet/latest/lang_defined_types.html"
712
- @logger.warn(message)
702
+ Bolt::Logger.warn("empty_manifest", message)
713
703
  end
714
704
 
715
705
  executor = Bolt::Executor.new(config.concurrency, analytics, noop, config.modified_concurrency)
@@ -745,7 +735,7 @@ module Bolt
745
735
  def generate_types
746
736
  assert_puppetfile_or_module_command(config.project.modules)
747
737
  # generate_types will surface a nice error with helpful message if it fails
748
- pal.generate_types
738
+ pal.generate_types(cache: true)
749
739
  0
750
740
  end
751
741
 
@@ -861,7 +851,7 @@ module Bolt
861
851
  elsif modules.nil? && options[:subcommand] == 'puppetfile'
862
852
  msg = "Command '#{old_command}' is deprecated and will be removed in Bolt 3.0. Update your project to use "\
863
853
  "the module management feature. For more information, see https://pup.pt/bolt-module-migrate."
864
- Bolt::Logger.deprecation_warning('puppetfile command', msg)
854
+ Bolt::Logger.deprecate("puppetfile_command", msg)
865
855
  elsif modules.nil? && options[:subcommand] == 'module'
866
856
  msg = "Unable to use command '#{new_command}' when 'modules' is not configured in "\
867
857
  "bolt-project.yaml. "
@@ -966,7 +956,7 @@ module Bolt
966
956
  set the BOLT_GEM environment variable.
967
957
  MSG
968
958
 
969
- @logger.warn(msg)
959
+ Bolt::Logger.warn("gem_install", msg)
970
960
  end
971
961
 
972
962
  # We only need to enumerate bundled content when running a task or plan
@@ -20,7 +20,7 @@ module Bolt
20
20
  class Config
21
21
  include Bolt::Config::Options
22
22
 
23
- attr_reader :config_files, :logs, :data, :transports, :project, :modified_concurrency, :deprecations
23
+ attr_reader :config_files, :data, :transports, :project, :modified_concurrency
24
24
 
25
25
  BOLT_CONFIG_NAME = 'bolt.yaml'
26
26
  BOLT_DEFAULTS_NAME = 'bolt-defaults.yaml'
@@ -33,9 +33,6 @@ module Bolt
33
33
  end
34
34
 
35
35
  def self.from_project(project, overrides = {})
36
- logs = []
37
- deprecations = []
38
-
39
36
  conf = if project.project_file == project.config_file
40
37
  project.data
41
38
  else
@@ -45,31 +42,26 @@ module Bolt
45
42
  # with all validation errors.
46
43
  Bolt::Validator.new.tap do |validator|
47
44
  validator.validate(c, bolt_schema, project.config_file.to_s)
48
-
49
- validator.warnings.each { |warning| logs << { warn: warning } }
50
-
51
- validator.deprecations.each do |dep|
52
- deprecations << { type: "#{BOLT_CONFIG_NAME} #{dep[:option]}", msg: dep[:message] }
53
- end
45
+ validator.warnings.each { |warning| Bolt::Logger.warn(warning[:id], warning[:msg]) }
46
+ validator.deprecations.each { |dep| Bolt::Logger.deprecate(dep[:id], dep[:msg]) }
54
47
  end
55
48
 
56
- logs << { debug: "Loaded configuration from #{project.config_file}" } if File.exist?(project.config_file)
49
+ if File.exist?(project.config_file)
50
+ Bolt::Logger.debug("Loaded configuration from #{project.config_file}")
51
+ end
57
52
  c
58
53
  end
54
+
59
55
  data = load_defaults(project).push(
60
- filepath: project.config_file,
61
- data: conf,
62
- logs: logs,
63
- deprecations: deprecations
56
+ filepath: project.config_file,
57
+ data: conf
64
58
  )
65
59
 
66
60
  new(project, data, overrides)
67
61
  end
68
62
 
69
63
  def self.from_file(configfile, overrides = {})
70
- project = Bolt::Project.create_project(Pathname.new(configfile).expand_path.dirname)
71
- logs = []
72
- deprecations = []
64
+ project = Bolt::Project.create_project(Pathname.new(configfile).expand_path.dirname)
73
65
 
74
66
  conf = if project.project_file == project.config_file
75
67
  project.data
@@ -80,23 +72,18 @@ module Bolt
80
72
  # with all validation errors.
81
73
  Bolt::Validator.new.tap do |validator|
82
74
  validator.validate(c, bolt_schema, project.config_file.to_s)
83
-
84
- validator.warnings.each { |warning| logs << { warn: warning } }
85
-
86
- validator.deprecations.each do |dep|
87
- deprecations << { type: "#{BOLT_CONFIG_NAME} #{dep[:option]}", msg: dep[:message] }
88
- end
75
+ validator.warnings.each { |warning| Bolt::Logger.warn(warning[:id], warning[:msg]) }
76
+ validator.deprecations.each { |dep| Bolt::Logger.deprecate(dep[:id], dep[:msg]) }
89
77
  end
90
78
 
91
- logs << { debug: "Loaded configuration from #{configfile}" }
79
+ Bolt::Logger.debug("Loaded configuration from #{configfile}")
80
+
92
81
  c
93
82
  end
94
83
 
95
84
  data = load_defaults(project).push(
96
- filepath: configfile,
97
- data: conf,
98
- logs: logs,
99
- deprecations: deprecations
85
+ filepath: configfile,
86
+ data: conf
100
87
  )
101
88
 
102
89
  new(project, data, overrides)
@@ -154,13 +141,14 @@ module Bolt
154
141
  def self.load_bolt_defaults_yaml(dir)
155
142
  filepath = dir + BOLT_DEFAULTS_NAME
156
143
  data = Bolt::Util.read_yaml_hash(filepath, 'config')
157
- logs = [{ debug: "Loaded configuration from #{filepath}" }]
158
- deprecations = []
144
+
145
+ Bolt::Logger.debug("Loaded configuration from #{filepath}")
159
146
 
160
147
  # Warn if 'bolt.yaml' detected in same directory.
161
148
  if File.exist?(bolt_yaml = dir + BOLT_CONFIG_NAME)
162
- logs.push(
163
- warn: "Detected multiple configuration files: ['#{bolt_yaml}', '#{filepath}']. '#{bolt_yaml}' "\
149
+ Bolt::Logger.warn(
150
+ "multiple_config_files",
151
+ "Detected multiple configuration files: ['#{bolt_yaml}', '#{filepath}']. '#{bolt_yaml}' "\
164
152
  "will be ignored."
165
153
  )
166
154
  end
@@ -169,12 +157,8 @@ module Bolt
169
157
  # with all validation errors.
170
158
  Bolt::Validator.new.tap do |validator|
171
159
  validator.validate(data, defaults_schema, filepath)
172
-
173
- validator.warnings.each { |warning| logs << { warn: warning } }
174
-
175
- validator.deprecations.each do |dep|
176
- deprecations << { type: "#{BOLT_DEFAULTS_NAME} #{dep[:option]}", msg: dep[:message] }
177
- end
160
+ validator.warnings.each { |warning| Bolt::Logger.warn(warning[:id], warning[:msg]) }
161
+ validator.deprecations.each { |dep| Bolt::Logger.deprecate(dep[:id], dep[:msg]) }
178
162
  end
179
163
 
180
164
  # Remove project-specific config such as hiera-config, etc.
@@ -182,8 +166,10 @@ module Bolt
182
166
 
183
167
  if project_config.any?
184
168
  data.reject! { |key, _| project_config.include?(key) }
185
- logs.push(
186
- warn: "Unsupported project configuration detected in '#{filepath}': #{project_config.keys}. "\
169
+
170
+ Bolt::Logger.warn(
171
+ "unsupported_project_config",
172
+ "Unsupported project configuration detected in '#{filepath}': #{project_config.keys}. "\
187
173
  "Project configuration should be set in 'bolt-project.yaml'."
188
174
  )
189
175
  end
@@ -193,8 +179,10 @@ module Bolt
193
179
 
194
180
  if transport_config.any?
195
181
  data.reject! { |key, _| transport_config.include?(key) }
196
- logs.push(
197
- warn: "Unsupported inventory configuration detected in '#{filepath}': #{transport_config.keys}. "\
182
+
183
+ Bolt::Logger.warn(
184
+ "unsupported_inventory_config",
185
+ "Unsupported inventory configuration detected in '#{filepath}': #{transport_config.keys}. "\
198
186
  "Transport configuration should be set under the 'inventory-config' option or "\
199
187
  "in 'inventory.yaml'."
200
188
  )
@@ -219,7 +207,7 @@ module Bolt
219
207
  data = data.merge(data.delete('inventory-config'))
220
208
  end
221
209
 
222
- { filepath: filepath, data: data, logs: logs, deprecations: deprecations }
210
+ { filepath: filepath, data: data }
223
211
  end
224
212
 
225
213
  # Loads a 'bolt.yaml' file, the legacy configuration file. There's no special munging needed
@@ -227,24 +215,24 @@ module Bolt
227
215
  def self.load_bolt_yaml(dir)
228
216
  filepath = dir + BOLT_CONFIG_NAME
229
217
  data = Bolt::Util.read_yaml_hash(filepath, 'config')
230
- logs = [{ debug: "Loaded configuration from #{filepath}" }]
231
- deprecations = [{ type: 'Using bolt.yaml for system configuration',
232
- msg: "Configuration file #{filepath} is deprecated and will be removed in Bolt 3.0. "\
233
- "See https://pup.pt/update-bolt-config for how to update to the latest Bolt practices." }]
218
+
219
+ Bolt::Logger.debug("Loaded configuration from #{filepath}")
220
+
221
+ Bolt::Logger.deprecate(
222
+ "bolt_yaml",
223
+ "Configuration file #{filepath} is deprecated and will be removed in Bolt 3.0. "\
224
+ "See https://pup.pt/update-bolt-config for how to update to the latest Bolt practices."
225
+ )
234
226
 
235
227
  # Validate the config against the schema. This will raise a single error
236
228
  # with all validation errors.
237
229
  Bolt::Validator.new.tap do |validator|
238
230
  validator.validate(data, bolt_schema, filepath)
239
-
240
- validator.warnings.each { |warning| logs << { warn: warning } }
241
-
242
- validator.deprecations.each do |dep|
243
- deprecations << { type: "#{BOLT_CONFIG_NAME} #{dep[:option]}", msg: dep[:message] }
244
- end
231
+ validator.warnings.each { |warning| Bolt::Logger.warn(warning[:id], warning[:msg]) }
232
+ validator.deprecations.each { |dep| Bolt::Logger.deprecate(dep[:id], dep[:msg]) }
245
233
  end
246
234
 
247
- { filepath: filepath, data: data, logs: logs, deprecations: deprecations }
235
+ { filepath: filepath, data: data }
248
236
  end
249
237
 
250
238
  def self.load_defaults(project)
@@ -275,16 +263,11 @@ module Bolt
275
263
 
276
264
  def initialize(project, config_data, overrides = {})
277
265
  unless config_data.is_a?(Array)
278
- config_data = [{ filepath: project.config_file,
279
- data: config_data,
280
- logs: [],
281
- deprecations: [] }]
266
+ config_data = [{ filepath: project.config_file, data: config_data }]
282
267
  end
283
268
 
284
269
  @logger = Bolt::Logger.logger(self)
285
270
  @project = project
286
- @logs = @project.logs.dup
287
- @deprecations = @project.deprecations.dup
288
271
  @transports = {}
289
272
  @config_files = []
290
273
 
@@ -294,6 +277,7 @@ module Bolt
294
277
  'color' => true,
295
278
  'compile-concurrency' => Etc.nprocessors,
296
279
  'concurrency' => default_concurrency,
280
+ 'disable-warnings' => [],
297
281
  'format' => 'human',
298
282
  'log' => { 'console' => {} },
299
283
  'module-install' => {},
@@ -315,9 +299,6 @@ module Bolt
315
299
  end
316
300
 
317
301
  loaded_data = config_data.each_with_object([]) do |data, acc|
318
- @logs.concat(data[:logs]) if data[:logs].any?
319
- @deprecations.concat(data[:deprecations]) if data[:deprecations].any?
320
-
321
302
  if data[:data].any?
322
303
  @config_files.push(data[:filepath])
323
304
  acc.push(data[:data])
@@ -388,6 +369,9 @@ module Bolt
388
369
  # Hash values are shallow merged
389
370
  when 'puppetdb', 'plugin-hooks', 'plugin_hooks', 'apply-settings', 'apply_settings', 'log'
390
371
  val1.merge(val2)
372
+ # Disabled warnings are concatenated
373
+ when 'disable-warnings'
374
+ val1.concat(val2)
391
375
  # All other values are overwritten
392
376
  else
393
377
  val2
@@ -452,17 +436,19 @@ module Bolt
452
436
 
453
437
  next unless acc[name][:level] == 'notice'
454
438
 
455
- @deprecations << {
456
- type: 'notice log level',
457
- msg: "Log level 'notice' is deprecated and will be removed in Bolt 3.0. Use 'info' instead."
458
- }
439
+ Bolt::Logger.deprecate(
440
+ "notice_log_level",
441
+ "Log level 'notice' is deprecated and will be removed in Bolt 3.0. Use 'info' instead."
442
+ )
459
443
  end
460
444
  end
461
445
 
462
446
  def validate
463
447
  if @data['future']
464
- msg = "Configuration option 'future' no longer exposes future behavior."
465
- @logs << { warn: msg }
448
+ Bolt::Logger.warn(
449
+ "future_option",
450
+ "Configuration option 'future' no longer exposes future behavior."
451
+ )
466
452
  end
467
453
 
468
454
  if @project.modules && @data['modulepath']&.include?(@project.managed_moduledir.to_s)
@@ -489,18 +475,30 @@ module Bolt
489
475
  # settings can be set at the user or system level.
490
476
  if @project.modules && puppetfile_config.any? && module_install.empty?
491
477
  command = Bolt::Util.powershell? ? 'Update-BoltProject' : 'bolt project migrate'
492
- @logs << { warn: "Detected configuration for 'puppetfile'. This setting is not "\
493
- "used when 'modules' is configured. Use 'module-install' instead. "\
494
- "To automatically update your project configuration, run '#{command}'." }
478
+ Bolt::Logger.warn(
479
+ "module_install_config",
480
+ "Detected configuration for 'puppetfile'. This setting is not "\
481
+ "used when 'modules' is configured. Use 'module-install' instead. "\
482
+ "To automatically update your project configuration, run '#{command}'."
483
+ )
495
484
  elsif @project.modules.nil? && puppetfile_config.empty? && module_install.any?
496
- @logs << { warn: "Detected configuration for 'module-install'. This setting is not "\
497
- "used when 'modules' is not configured. Use 'puppetfile' instead." }
485
+ Bolt::Logger.warn(
486
+ "module_install_config",
487
+ "Detected configuration for 'module-install'. This setting is not "\
488
+ "used when 'modules' is not configured. Use 'puppetfile' instead."
489
+ )
498
490
  elsif @project.modules && puppetfile_config.any? && module_install.any?
499
- @logs << { warn: "Detected configuration for 'puppetfile' and 'module-install'. Using "\
500
- "configuration for 'module-install' because 'modules' is also configured." }
491
+ Bolt::Logger.warn(
492
+ "module_install_config",
493
+ "Detected configuration for 'puppetfile' and 'module-install'. Using "\
494
+ "configuration for 'module-install' because 'modules' is also configured."
495
+ )
501
496
  elsif @project.modules.nil? && puppetfile_config.any? && module_install.any?
502
- @logs << { warn: "Detected configuration for 'puppetfile' and 'module-install'. Using "\
503
- "configuration for 'puppetfile' because 'modules' is not configured." }
497
+ Bolt::Logger.warn(
498
+ "module_install_config",
499
+ "Detected configuration for 'puppetfile' and 'module-install'. Using "\
500
+ "configuration for 'puppetfile' because 'modules' is not configured."
501
+ )
504
502
  end
505
503
  end
506
504
 
@@ -593,7 +591,7 @@ module Bolt
593
591
  def plugin_hooks
594
592
  if @data['plugin-hooks'].any? && @data['plugin_hooks'].any?
595
593
  Bolt::Logger.warn_once(
596
- "plugin-hooks and plugin_hooks set",
594
+ "plugin_hooks_conflict",
597
595
  "Detected configuration for 'plugin-hooks' and 'plugin_hooks'. Bolt will ignore 'plugin_hooks'."
598
596
  )
599
597
 
@@ -612,7 +610,7 @@ module Bolt
612
610
  def apply_settings
613
611
  if @data['apply-settings'].any? && @data['apply_settings'].any?
614
612
  Bolt::Logger.warn_once(
615
- "apply-settings and apply_settings set",
613
+ "apply_settings_conflict",
616
614
  "Detected configuration for 'apply-settings' and 'apply_settings'. Bolt will ignore 'apply_settings'."
617
615
  )
618
616
 
@@ -632,6 +630,10 @@ module Bolt
632
630
  @project.module_install || @data['module-install']
633
631
  end
634
632
 
633
+ def disable_warnings
634
+ Set.new(@project.disable_warnings + @data['disable-warnings'])
635
+ end
636
+
635
637
  # Check if there is a case-insensitive match to the path
636
638
  def check_path_case(type, paths)
637
639
  return if paths.nil?
@@ -640,7 +642,7 @@ module Bolt
640
642
  if matches.any?
641
643
  msg = "WARNING: Bolt is case sensitive when specifying a #{type}. Did you mean:\n"
642
644
  matches.each { |path| msg += " #{path}\n" }
643
- @logger.warn msg
645
+ Bolt::Logger.warn("path_case", msg)
644
646
  end
645
647
  end
646
648