bolt 0.8.0 → 0.9.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bolt/cli.rb +31 -21
  3. data/lib/bolt/config.rb +1 -0
  4. data/lib/bolt/error.rb +28 -0
  5. data/lib/bolt/executor.rb +10 -6
  6. data/lib/bolt/node.rb +7 -5
  7. data/lib/bolt/node/errors.rb +25 -3
  8. data/lib/bolt/node/orch.rb +7 -16
  9. data/lib/bolt/node/output.rb +17 -0
  10. data/lib/bolt/node/ssh.rb +101 -44
  11. data/lib/bolt/node/winrm.rb +86 -40
  12. data/lib/bolt/outputter/human.rb +65 -8
  13. data/lib/bolt/outputter/json.rb +8 -1
  14. data/lib/bolt/result.rb +74 -124
  15. data/lib/bolt/version.rb +1 -1
  16. data/{vendored/puppet → modules/boltlib}/lib/puppet/functions/file_upload.rb +9 -7
  17. data/{vendored/puppet → modules/boltlib}/lib/puppet/functions/run_command.rb +8 -9
  18. data/{vendored/puppet → modules/boltlib}/lib/puppet/functions/run_plan.rb +8 -12
  19. data/{vendored/puppet → modules/boltlib}/lib/puppet/functions/run_script.rb +12 -8
  20. data/{vendored/puppet → modules/boltlib}/lib/puppet/functions/run_task.rb +10 -10
  21. data/vendored/puppet/lib/puppet/agent.rb +1 -1
  22. data/vendored/puppet/lib/puppet/application/lookup.rb +1 -3
  23. data/vendored/puppet/lib/puppet/configurer.rb +2 -3
  24. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +25 -7
  25. data/vendored/puppet/lib/puppet/defaults.rb +9 -1
  26. data/vendored/puppet/lib/puppet/face/epp.rb +4 -2
  27. data/vendored/puppet/lib/puppet/face/module/build.rb +1 -1
  28. data/vendored/puppet/lib/puppet/face/module/list.rb +5 -16
  29. data/vendored/puppet/lib/puppet/face/module/uninstall.rb +14 -3
  30. data/vendored/puppet/lib/puppet/face/plugin.rb +1 -3
  31. data/vendored/puppet/lib/puppet/forge/errors.rb +17 -7
  32. data/vendored/puppet/lib/puppet/functions.rb +8 -6
  33. data/vendored/puppet/lib/puppet/functions/each.rb +10 -4
  34. data/vendored/puppet/lib/puppet/functions/lookup.rb +2 -2
  35. data/vendored/puppet/lib/puppet/functions/map.rb +12 -2
  36. data/vendored/puppet/lib/puppet/functions/slice.rb +2 -3
  37. data/vendored/puppet/lib/puppet/graph/simple_graph.rb +9 -5
  38. data/vendored/puppet/lib/puppet/interface.rb +1 -0
  39. data/vendored/puppet/lib/puppet/module_tool/errors/installer.rb +27 -17
  40. data/vendored/puppet/lib/puppet/module_tool/errors/shared.rb +143 -63
  41. data/vendored/puppet/lib/puppet/module_tool/errors/uninstaller.rb +37 -14
  42. data/vendored/puppet/lib/puppet/module_tool/errors/upgrader.rb +30 -18
  43. data/vendored/puppet/lib/puppet/network/auth_config_parser.rb +8 -8
  44. data/vendored/puppet/lib/puppet/network/http/error.rb +7 -7
  45. data/vendored/puppet/lib/puppet/network/http/rack.rb +2 -2
  46. data/vendored/puppet/lib/puppet/network/http/webrick.rb +1 -1
  47. data/vendored/puppet/lib/puppet/node.rb +10 -0
  48. data/vendored/puppet/lib/puppet/node/facts.rb +9 -0
  49. data/vendored/puppet/lib/puppet/parameter/value_collection.rb +16 -6
  50. data/vendored/puppet/lib/puppet/parser/resource.rb +103 -31
  51. data/vendored/puppet/lib/puppet/pops/evaluator/access_operator.rb +13 -0
  52. data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +22 -6
  53. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +1 -1
  54. data/vendored/puppet/lib/puppet/pops/lookup/lookup_adapter.rb +13 -4
  55. data/vendored/puppet/lib/puppet/pops/model/ast_transformer.rb +1 -1
  56. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +527 -529
  57. data/vendored/puppet/lib/puppet/pops/serialization/abstract_reader.rb +4 -0
  58. data/vendored/puppet/lib/puppet/pops/serialization/abstract_writer.rb +6 -0
  59. data/vendored/puppet/lib/puppet/pops/serialization/extension.rb +1 -0
  60. data/vendored/puppet/lib/puppet/pops/serialization/serializer.rb +2 -1
  61. data/vendored/puppet/lib/puppet/pops/types/execution_result.rb +8 -0
  62. data/vendored/puppet/lib/puppet/pops/types/iterable.rb +2 -0
  63. data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +3 -0
  64. data/vendored/puppet/lib/puppet/pops/types/p_object_type_extension.rb +6 -0
  65. data/vendored/puppet/lib/puppet/pops/types/p_uri_type.rb +191 -0
  66. data/vendored/puppet/lib/puppet/pops/types/string_converter.rb +17 -0
  67. data/vendored/puppet/lib/puppet/pops/types/type_calculator.rb +5 -0
  68. data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +7 -0
  69. data/vendored/puppet/lib/puppet/pops/types/type_formatter.rb +16 -18
  70. data/vendored/puppet/lib/puppet/pops/types/type_mismatch_describer.rb +15 -5
  71. data/vendored/puppet/lib/puppet/pops/types/type_parser.rb +6 -0
  72. data/vendored/puppet/lib/puppet/pops/types/type_with_members.rb +43 -0
  73. data/vendored/puppet/lib/puppet/pops/types/types.rb +3 -0
  74. data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
  75. data/vendored/puppet/lib/puppet/provider/package/nim.rb +7 -8
  76. data/vendored/puppet/lib/puppet/provider/package/opkg.rb +1 -1
  77. data/vendored/puppet/lib/puppet/provider/package/pkg.rb +6 -4
  78. data/vendored/puppet/lib/puppet/provider/package/pkgutil.rb +3 -3
  79. data/vendored/puppet/lib/puppet/provider/service/init.rb +1 -1
  80. data/vendored/puppet/lib/puppet/syntax_checkers/base64.rb +5 -6
  81. data/vendored/puppet/lib/puppet/transaction.rb +1 -1
  82. data/vendored/puppet/lib/puppet/type.rb +1 -9
  83. data/vendored/puppet/lib/puppet/type/schedule.rb +1 -1
  84. data/vendored/puppet/lib/puppet/util/log.rb +2 -3
  85. data/vendored/puppet/lib/puppet/util/plist.rb +1 -1
  86. data/vendored/puppet/lib/puppet/util/reference.rb +2 -3
  87. data/vendored/puppet/lib/puppet_pal.rb +326 -53
  88. metadata +28 -12
  89. data/lib/bolt/node/result.rb +0 -115
  90. data/vendored/puppet/lib/puppet/configurer/downloader_factory.rb +0 -44
@@ -11,13 +11,22 @@ module Puppet::ModuleTool::Errors
11
11
  end
12
12
 
13
13
  def multiline
14
- message = []
15
- message << _("Could not uninstall module '%{module_name}' (%{version})") % { module_name: @module_name, version: v(@version) }
16
- message << _(" No installed version of '%{module_name}' matches (%{version})") % { module_name: @module_name, version: v(@version) }
17
- message += @modules.map do |mod|
14
+ module_versions_list = @modules.map do |mod|
18
15
  _(" '%{module_name}' (%{version}) is installed in %{path}") % { module_name: mod[:name], version: v(mod[:version]), path: mod[:path] }
16
+ end.join("\n")
17
+
18
+ if module_versions_list.empty?
19
+ _(<<-MSG).chomp % { module_name: @module_name, version: v(@version)}
20
+ Could not uninstall module '%{module_name}' (%{version})
21
+ No installed version of '%{module_name}' matches (%{version})
22
+ MSG
23
+ else
24
+ _(<<-MSG).chomp % { module_name: @module_name, version: v(@version), module_versions_list: module_versions_list }
25
+ Could not uninstall module '%{module_name}' (%{version})
26
+ No installed version of '%{module_name}' matches (%{version})
27
+ %{module_versions_list}
28
+ MSG
19
29
  end
20
- message.join("\n")
21
30
  end
22
31
  end
23
32
 
@@ -32,18 +41,32 @@ module Puppet::ModuleTool::Errors
32
41
  end
33
42
 
34
43
  def multiline
35
- message = []
44
+
45
+ module_requirements_list = @required_by.map do |mod|
46
+ msg_variables = { module_name: mod['name'], version: v(mod['version']), module_dependency: @module_name,
47
+ dependency_version: v(mod['version_requirement']) }
48
+ _(" '%{module_name}' (%{version}) requires '%{module_dependency}' (%{dependency_version})") % msg_variables
49
+ end.join("\n")
50
+
36
51
  if @requested_version
37
- message << _("Could not uninstall module '%{module_name}' (v%{requested_version})") % { module_name: @module_name, requested_version: @requested_version }
52
+ msg_variables = { module_name: @module_name, requested_version: @requested_version, version: v(@installed_version),
53
+ module_requirements_list: module_requirements_list }
54
+ #TRANSLATORS `puppet module uninstall --force` is a command line option that should not be translated
55
+ _(<<-EOF).chomp % msg_variables
56
+ Could not uninstall module '%{module_name}' (v%{requested_version})
57
+ Other installed modules have dependencies on '%{module_name}' (%{version})
58
+ %{module_requirements_list}
59
+ Use `puppet module uninstall --force` to uninstall this module anyway
60
+ EOF
38
61
  else
39
- message << _("Could not uninstall module '%{module_name}'") % { module_name: @module_name }
40
- end
41
- message << _(" Other installed modules have dependencies on '%{module_name}' (%{version})") % { module_name: @module_name, version: v(@installed_version) }
42
- message += @required_by.map do |mod|
43
- _(" '%{module_name}' (%{version}) requires '%{module_dep}' (%{dep_version})") % { module_name: mod['name'], version: v(mod['version']), module_dep: @module_name, dep_version: v(mod['version_requirement']) }
62
+ #TRANSLATORS `puppet module uninstall --force` is a command line option that should not be translated
63
+ _(<<-EOF) % { module_name: @module_name, version: v(@installed_version), module_requirements_list: module_requirements_list }
64
+ Could not uninstall module '%{module_name}'
65
+ Other installed modules have dependencies on '%{module_name}' (%{version})
66
+ %{module_requirements_list}
67
+ Use `puppet module uninstall --force` to uninstall this module anyway
68
+ EOF
44
69
  end
45
- message << _(" Use `puppet module uninstall --force` to uninstall this module anyway")
46
- message.join("\n")
47
70
  end
48
71
  end
49
72
  end
@@ -21,23 +21,36 @@ module Puppet::ModuleTool::Errors
21
21
  end
22
22
 
23
23
  def multiline
24
- message = []
25
- message << _("Could not upgrade module '%{module_name}' (%{version})") % { module_name: @module_name, version: vstring }
26
24
  if @newer_versions.empty?
27
- message << _(" The installed version is already the latest version matching %{version}") % { version: vstring }
25
+ # TRANSLATORS `puppet module upgrade --force` is a command line option that should not be translated
26
+ _(<<-MSG).chomp % { module_name: @module_name, version: vstring }
27
+ Could not upgrade module '%{module_name}' (%{version})
28
+ The installed version is already the latest version matching %{version}
29
+ Use `puppet module upgrade --force` to upgrade only this module
30
+ MSG
28
31
  else
29
- message << _(" There are %{count} newer versions") % { count: @newer_versions.length }
30
- message << _(" No combination of dependency upgrades would satisfy all dependencies")
31
- unless @possible_culprits.empty?
32
- message << _(" Dependencies will not be automatically upgraded across major versions")
33
- message << _(" Upgrading one or more of these modules may permit the upgrade to succeed:")
34
- @possible_culprits.each do |name|
35
- message << " - #{name}"
36
- end
32
+ if @possible_culprits.empty?
33
+ # TRANSLATORS `puppet module upgrade --force` is a command line option that should not be translated
34
+ _(<<-MSG).chomp % { module_name: @module_name, version: vstring, count: @newer_versions.length }
35
+ Could not upgrade module '%{module_name}' (%{version})
36
+ There are %{count} newer versions
37
+ No combination of dependency upgrades would satisfy all dependencies
38
+ Use `puppet module upgrade --force` to upgrade only this module
39
+ MSG
40
+ else
41
+ module_dependency_list = @possible_culprits.map {|name| " - #{name}"}.join("\n")
42
+ # TRANSLATORS `puppet module upgrade --force` is a command line option that should not be translated
43
+ _(<<-MSG).chomp % { module_name: @module_name, version: vstring, count: @newer_versions.length, module_dependency_list: module_dependency_list }
44
+ Could not upgrade module '%{module_name}' (%{version})
45
+ There are %{count} newer versions
46
+ No combination of dependency upgrades would satisfy all dependencies
47
+ Dependencies will not be automatically upgraded across major versions
48
+ Upgrading one or more of these modules may permit the upgrade to succeed:
49
+ %{module_dependency_list}
50
+ Use `puppet module upgrade --force` to upgrade only this module
51
+ MSG
37
52
  end
38
53
  end
39
- message << _(" Use `puppet module upgrade --force` to upgrade only this module")
40
- message.join("\n")
41
54
  end
42
55
  end
43
56
 
@@ -53,11 +66,10 @@ module Puppet::ModuleTool::Errors
53
66
  end
54
67
 
55
68
  def multiline
56
- message = []
57
- message << _("Could not %{action} module '%{module_name}' (%{version})") % { action: @action, module_name: @module_name, version: vstring }
58
- message << _(" Downgrading is not allowed.")
59
-
60
- message.join("\n")
69
+ _(<<-MSG).chomp % { action: @action, module_name: @module_name, version: vstring }
70
+ Could not %{action} module '%{module_name}' (%{version})
71
+ Downgrading is not allowed.
72
+ MSG
61
73
  end
62
74
  end
63
75
  end
@@ -51,19 +51,19 @@ class AuthConfigParser
51
51
  value.strip!
52
52
  case var
53
53
  when "allow"
54
- modify_right(right, :allow, value, _("allowing %s access"), count)
54
+ modify_right(right, :allow, value, _("allowing %{value} access"), count)
55
55
  when "deny"
56
- modify_right(right, :deny, value, _("denying %s access"), count)
56
+ modify_right(right, :deny, value, _("denying %{value} access"), count)
57
57
  when "allow_ip"
58
- modify_right(right, :allow_ip, value, _("allowing IP %s access"), count)
58
+ modify_right(right, :allow_ip, value, _("allowing IP %{value} access"), count)
59
59
  when "deny_ip"
60
- modify_right(right, :deny_ip, value, _("denying IP %s access"), count)
60
+ modify_right(right, :deny_ip, value, _("denying IP %{value} access"), count)
61
61
  when "method"
62
- modify_right(right, :restrict_method, value, _("allowing 'method' %s"), count)
62
+ modify_right(right, :restrict_method, value, _("allowing 'method' %{value}"), count)
63
63
  when "environment"
64
- modify_right(right, :restrict_environment, value, _("adding environment %s"), count)
64
+ modify_right(right, :restrict_environment, value, _("adding environment %{value}"), count)
65
65
  when /auth(?:enticated)?/
66
- modify_right(right, :restrict_authenticated, value, _("adding authentication %s"), count)
66
+ modify_right(right, :restrict_authenticated, value, _("adding authentication %{value}"), count)
67
67
  else
68
68
  raise Puppet::ConfigurationError,
69
69
  _("Invalid argument '%{var}' at line %{count}") % { var: var, count: count }
@@ -74,7 +74,7 @@ class AuthConfigParser
74
74
  value.split(/\s*,\s*/).each do |val|
75
75
  begin
76
76
  val.strip!
77
- right.info msg % val
77
+ right.info msg % { value: val }
78
78
  right.send(method, val)
79
79
  rescue Puppet::AuthStoreError => detail
80
80
  raise Puppet::ConfigurationError, _("%{detail} at line %{count} of %{file}") % { detail: detail, count: count, file: @file }, detail.backtrace
@@ -20,42 +20,42 @@ module Puppet::Network::HTTP::Error
20
20
  class HTTPNotAcceptableError < HTTPError
21
21
  CODE = 406
22
22
  def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
23
- super(_("Not Acceptable: ") + message, CODE, issue_kind)
23
+ super(_("Not Acceptable: %{message}") % { message: message }, CODE, issue_kind)
24
24
  end
25
25
  end
26
26
 
27
27
  class HTTPNotFoundError < HTTPError
28
28
  CODE = 404
29
29
  def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
30
- super(_("Not Found: ") + message, CODE, issue_kind)
30
+ super(_("Not Found: %{message}") % { message: message }, CODE, issue_kind)
31
31
  end
32
32
  end
33
33
 
34
34
  class HTTPNotAuthorizedError < HTTPError
35
35
  CODE = 403
36
36
  def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
37
- super(_("Not Authorized: ") + message, CODE, issue_kind)
37
+ super(_("Not Authorized: %{message}") % { message: message }, CODE, issue_kind)
38
38
  end
39
39
  end
40
40
 
41
41
  class HTTPBadRequestError < HTTPError
42
42
  CODE = 400
43
43
  def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
44
- super(_("Bad Request: ") + message, CODE, issue_kind)
44
+ super(_("Bad Request: %{message}") % { message: message }, CODE, issue_kind)
45
45
  end
46
46
  end
47
47
 
48
48
  class HTTPMethodNotAllowedError < HTTPError
49
49
  CODE = 405
50
50
  def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
51
- super(_("Method Not Allowed: ") + message, CODE, issue_kind)
51
+ super(_("Method Not Allowed: %{message}") % { message: message }, CODE, issue_kind)
52
52
  end
53
53
  end
54
54
 
55
55
  class HTTPUnsupportedMediaTypeError < HTTPError
56
56
  CODE = 415
57
57
  def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
58
- super(_("Unsupported Media Type: ") + message, CODE, issue_kind)
58
+ super(_("Unsupported Media Type: %{message}") % { message: message }, CODE, issue_kind)
59
59
  end
60
60
  end
61
61
 
@@ -63,7 +63,7 @@ module Puppet::Network::HTTP::Error
63
63
  CODE = 500
64
64
 
65
65
  def initialize(original_error, issue_kind = Issues::RUNTIME_ERROR)
66
- super(_("Server Error: ") + original_error.message, CODE, issue_kind)
66
+ super(_("Server Error: %{message}") % { message: original_error.message }, CODE, issue_kind)
67
67
  end
68
68
 
69
69
  def to_json
@@ -23,9 +23,9 @@ class Puppet::Network::HTTP::Rack
23
23
  # Send a Status 500 Error on unhandled exceptions.
24
24
  response.status = 500
25
25
  response['Content-Type'] = 'text/plain'
26
- response.write _('Internal Server Error: "%s"') % detail.message
26
+ response.write _("Internal Server Error: \"%{message}\"") % { message: detail.message }
27
27
  # log what happened
28
- Puppet.log_exception(detail, _("Puppet Server (Rack): Internal Server Error: Unhandled Exception: \"%s\"") % detail.message)
28
+ Puppet.log_exception(detail, _("Puppet Server (Rack): Internal Server Error: Unhandled Exception: \"%{message}\"") % { message: detail.message })
29
29
  end
30
30
  response.finish
31
31
  end
@@ -27,7 +27,7 @@ class Puppet::Network::HTTP::WEBrick
27
27
  @server.start do |sock|
28
28
  timeout = 10.0
29
29
  if ! IO.select([sock],nil,nil,timeout)
30
- raise _("Client did not send data within %.1f seconds of connecting") % timeout
30
+ raise _("Client did not send data within %{timeout} seconds of connecting") % { timeout: ("%.1f") % timeout }
31
31
  end
32
32
  sock.accept
33
33
  @server.run(sock)
@@ -149,6 +149,16 @@ class Puppet::Node
149
149
  @parameters[ENVIRONMENT] ||= self.environment.name.to_s
150
150
  end
151
151
 
152
+ # Add extra facts, such as facts given to lookup on the command line The
153
+ # extra facts will override existing ones.
154
+ # @param extra_facts [Hash{String=>Object}] the facts to tadd
155
+ # @api private
156
+ def add_extra_facts(extra_facts)
157
+ @facts.add_extra_values(extra_facts)
158
+ @parameters.merge!(extra_facts)
159
+ nil
160
+ end
161
+
152
162
  def add_server_facts(facts)
153
163
  # Append the current environment to the list of server facts
154
164
  @server_facts = facts.merge({ "environment" => self.environment.name.to_s})
@@ -59,6 +59,15 @@ class Puppet::Node::Facts
59
59
  end
60
60
  end
61
61
 
62
+ # Add extra values, such as facts given to lookup on the command line. The
63
+ # extra values will override existing values.
64
+ # @param extra_values [Hash{String=>Object}] the values to add
65
+ # @api private
66
+ def add_extra_values(extra_values)
67
+ @values.merge!(extra_values)
68
+ nil
69
+ end
70
+
62
71
  # Sanitize fact values by converting everything not a string, Boolean
63
72
  # numeric, array or hash into strings.
64
73
  def sanitize
@@ -181,12 +181,22 @@ class Puppet::Parameter::ValueCollection
181
181
  return if empty?
182
182
 
183
183
  unless @values.detect { |name, v| v.match?(value) }
184
- str = _("Invalid value %{value}. ") % { value: value.inspect }
185
-
186
- str += _("Valid values are %{value_list}. ") % { value_list: values.join(", ") } unless values.empty?
187
-
188
- str += _("Valid values match %{pattern}.") % { pattern: regexes.join(", ") } unless regexes.empty?
189
-
184
+ str = if values.empty?
185
+ if regexes.empty?
186
+ _("Invalid value %{value}.") % { value: value.inspect }
187
+ else
188
+ _("Invalid value %{value}. Valid values match %{patterns_list}.") %
189
+ { value: value.inspect, patterns_list: regexes.join(", ") }
190
+ end
191
+ else
192
+ if regexes.empty?
193
+ _("Invalid value %{value}. Valid values are %{values_list}.") %
194
+ { value: value.inspect, values_list: values.join(", ") }
195
+ else
196
+ _("Invalid value %{value}. Valid values are %{values_list}. Valid values match %{patterns_list}.") %
197
+ { value: value.inspect, values_list: values.join(", "), patterns_list: regexes.join(", ") }
198
+ end
199
+ end
190
200
  raise ArgumentError, str
191
201
  end
192
202
  end
@@ -171,11 +171,72 @@ class Puppet::Parser::Resource < Puppet::Resource
171
171
  if evaluated?
172
172
  strict = Puppet[:strict]
173
173
  unless strict == :off
174
- msg = _('Attempt to override an already evaluated resource%{location} with new values') %
175
- { resource: ref, location: append_location(file, line, _(', defined'), ',') }
176
- raise Puppet::ParseError.new(msg, resource.file, resource.line) if strict == :error
177
- msg << append_location(resource.file, resource.line)
178
- Puppet.warning(msg)
174
+ if strict == :error
175
+ msg = if file && file != ''
176
+ if line
177
+ _('Attempt to override an already evaluated resource, defined at %{file}:%{line}, with new values') % { file: file, line: line }
178
+ else
179
+ _('Attempt to override an already evaluated resource, defined in %{file}, with new values') % { file: file }
180
+ end
181
+ else
182
+ if line
183
+ _('Attempt to override an already evaluated resource, defined at line %{line}, with new values') % { line: line }
184
+ else
185
+ _('Attempt to override an already evaluated resource with new values')
186
+ end
187
+ end
188
+ raise Puppet::ParseError.new(msg, resource.file, resource.line)
189
+ else
190
+ msg = case
191
+ # all 4 variables set
192
+ when file && file != '' && line && resource.file && resource.file != '' && resource.line
193
+ _('Attempt to override an already evaluated resource, defined at %{file}:%{line}, with new values at %{resource_file}:%{resource_line}') %
194
+ { file: file, line: line, resource_file: resource.file, resource_line: resource.line }
195
+
196
+ # 3 variables set
197
+ when file && file != '' && line && resource.file && resource.file != ''
198
+ _('Attempt to override an already evaluated resource, defined at %{file}:%{line}, with new values in %{resource_file}') %
199
+ { file: file, line: line, resource_file: resource.file }
200
+ when file && file != '' && line && resource.line
201
+ _('Attempt to override an already evaluated resource, defined at %{file}:%{line}, with new values at line %{resource_line}') %
202
+ { file: file, line: line, resource_line: resource.line }
203
+ when file && file != '' && resource.file && resource.file != '' && resource.line
204
+ _('Attempt to override an already evaluated resource, defined in %{file}, with new values at %{resource_file}:%{resource_line}') %
205
+ { file: file, resource_file: resource.file, resource_line: resource.line }
206
+ when line && resource.file && resource.file != '' && resource.line
207
+ _('Attempt to override an already evaluated resource, defined at line %{line}, with new values at %{resource_file}:%{resource_line}') %
208
+ { line: line, resource_file: resource.file, resource_line: resource.line }
209
+
210
+ # 2 variables set
211
+ when file && file != '' && line
212
+ _('Attempt to override an already evaluated resource, defined at %{file}:%{line}, with new values') % { file: file, line: line }
213
+ when file && file != '' && resource.file && resource.file != ''
214
+ _('Attempt to override an already evaluated resource, defined in %{file}, with new values in %{resource_file}') % { file: file, resource_file: resource.file }
215
+ when file && file != '' && resource.line
216
+ _('Attempt to override an already evaluated resource, defined in %{file}, with new values at line %{resource_line}') % { file: file, resource_line: resource.line }
217
+ when line && resource.file && resource.file != ''
218
+ _('Attempt to override an already evaluated resource, defined at line %{line}, with new values in %{resource_file}') % { line: line, resource_file: resource.file }
219
+ when line && resource.line
220
+ _('Attempt to override an already evaluated resource, defined at line %{line}, with new values at line %{resource_line}') % { line: line, resource_line: resource.line }
221
+ when resource.file && resource.file != '' && resource.line
222
+ _('Attempt to override an already evaluated resource with new values at %{resource_file}:%{resource_line}') % { resource_file: resource.file, resource_line: resource.line }
223
+
224
+ # 1 variable set
225
+ when file && file != ''
226
+ _('Attempt to override an already evaluated resource, defined in %{file}, with new values') % { file: file }
227
+ when line
228
+ _('Attempt to override an already evaluated resource, defined at line %{line}, with new values') % { line: line }
229
+ when resource.file && resource.file != ''
230
+ _('Attempt to override an already evaluated resource with new values in %{resource_file}') % { resource_file: resource.file }
231
+ when resource.line
232
+ _('Attempt to override an already evaluated resource with new values at line %{resource_line}') % { resource_line: resource.line }
233
+
234
+ else
235
+ # no variables set
236
+ _('Attempt to override an already evaluated resource with new values')
237
+ end
238
+ Puppet.warning(msg)
239
+ end
179
240
  end
180
241
  end
181
242
 
@@ -322,28 +383,6 @@ class Puppet::Parser::Resource < Puppet::Resource
322
383
 
323
384
  private
324
385
 
325
- # Append location to the message if location is present. If it is not, an empty string
326
- # is returned instead.
327
- #
328
- # @param file [String] path to the file
329
- # @param line [Integer] the line in the file
330
- # @param prefix [String] string prefix
331
- # @param suffix [String] string suffix
332
- # @return [String] the formatted location or an empty string
333
- def append_location(file, line, prefix = '', suffix = '')
334
- if file && file != ''
335
- if line
336
- _('%{prefix} at %{file}:%{line}%{suffix}') % { prefix: prefix, suffix: suffix, file: file, line: line }
337
- else
338
- _('%{prefix} in %{file}%{suffix}') % { prefix: prefix, suffix: suffix, file: file }
339
- end
340
- elsif line
341
- _('%{prefix} at line %{line}%{suffix}') % { prefix: prefix, suffix: suffix, line: line }
342
- else
343
- ''
344
- end
345
- end
346
-
347
386
  def add_scope_tags
348
387
  scope_resource = scope.resource
349
388
  unless scope_resource.nil? || scope_resource.equal?(self)
@@ -371,10 +410,43 @@ class Puppet::Parser::Resource < Puppet::Resource
371
410
 
372
411
  # The parameter is already set. Fail if they're not allowed to override it.
373
412
  unless param.source.child_of?(current.source) || param.source.equal?(current.source) && scope.is_default?(type, param.name, current.value)
374
- msg = _("Parameter '%{name}' is already set on %{resource}") % { name: param.name, resource: ref }
375
- msg << _(' by %{source}') % { source: current.source.to_s } unless current.source.to_s == ''
376
- msg << append_location(current.file, current.line)
377
- msg << _('; cannot redefine')
413
+ msg = if current.source.to_s == ''
414
+ if current.file && current.file != ''
415
+ if current.line
416
+ _("Parameter '%{name}' is already set on %{resource} at %{file}:%{line}; cannot redefine") %
417
+ { name: param.name, resource: ref, file: current.file, line: current.line }
418
+ else
419
+ _("Parameter '%{name}' is already set on %{resource} in %{file}; cannot redefine") %
420
+ { name: param.name, resource: ref, file: current.file }
421
+ end
422
+ else
423
+ if current.line
424
+ _("Parameter '%{name}' is already set on %{resource} at line %{line}; cannot redefine") %
425
+ { name: param.name, resource: ref, line: current.line }
426
+ else
427
+ _("Parameter '%{name}' is already set on %{resource}; cannot redefine") %
428
+ { name: param.name, resource: ref }
429
+ end
430
+ end
431
+ else
432
+ if current.file && current.file != ''
433
+ if current.line
434
+ _("Parameter '%{name}' is already set on %{resource} by %{source} at %{file}:%{line}; cannot redefine") %
435
+ { name: param.name, resource: ref, source: current.source.to_s, file: current.file, line: current.line }
436
+ else
437
+ _("Parameter '%{name}' is already set on %{resource} by %{source} in %{file}; cannot redefine") %
438
+ { name: param.name, resource: ref, source: current.source.to_s, file: current.file }
439
+ end
440
+ else
441
+ if current.line
442
+ _("Parameter '%{name}' is already set on %{resource} by %{source} at line %{line}; cannot redefine") %
443
+ { name: param.name, resource: ref, source: current.source.to_s, line: current.line }
444
+ else
445
+ _("Parameter '%{name}' is already set on %{resource} by %{source}; cannot redefine") %
446
+ { name: param.name, resource: ref, source: current.source.to_s }
447
+ end
448
+ end
449
+ end
378
450
  raise Puppet::ParseError.new(msg, param.file, param.line)
379
451
  end
380
452