summaryrefslogtreecommitdiff
path: root/lib/chef/provider
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2017-04-04 00:19:41 -0700
committerNoah Kantrowitz <noah@coderanger.net>2017-04-04 00:19:41 -0700
commitdbb339175b445bcd4dfd6c54bababf9dd7908993 (patch)
treecb3b3f7762d0fb9916946c77d25471ce96dca694 /lib/chef/provider
parente77023bdce2db2522f0320237c532e6c6eaa93a2 (diff)
downloadchef-dbb339175b445bcd4dfd6c54bababf9dd7908993.tar.gz
Cope with the common case of passing node[“whatever”] as template variables.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Diffstat (limited to 'lib/chef/provider')
-rw-r--r--lib/chef/provider/template/content.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/chef/provider/template/content.rb b/lib/chef/provider/template/content.rb
index 76a3e6d169..b40794564a 100644
--- a/lib/chef/provider/template/content.rb
+++ b/lib/chef/provider/template/content.rb
@@ -40,8 +40,12 @@ class Chef
visitor = lambda do |obj|
case obj
when Hash
+ # If this is an Attribute object, we need to change class otherwise
+ # we get the immutable behavior. This could probably be fixed by
+ # using Hash#transform_values once we only support Ruby 2.4.
+ obj_class = obj.is_a?(Chef::Node::ImmutableMash) ? Mash : obj.class
# Avoid mutating hashes in the resource in case we're changing anything.
- obj.each_with_object(obj.class.new) do |(key, value), memo|
+ obj.each_with_object(obj_class.new) do |(key, value), memo|
memo[key] = visitor.call(value)
end
when Array