summaryrefslogtreecommitdiff
path: root/lib/chef/provider/template/content.rb
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2017-04-03 23:02:04 -0500
committerNoah Kantrowitz <noah@coderanger.net>2017-04-03 23:02:04 -0500
commit2c6a8ead5225a44d334dcc70c33308ad7c7a0021 (patch)
tree9b6938d67ff3f47dcc3186f3f5d98ea491546d4f /lib/chef/provider/template/content.rb
parente3b9e67a880bcd658517f90a6add837c0e026798 (diff)
downloadchef-2c6a8ead5225a44d334dcc70c33308ad7c7a0021.tar.gz
Allow lazy{} to be used in template resource variables.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Diffstat (limited to 'lib/chef/provider/template/content.rb')
-rw-r--r--lib/chef/provider/template/content.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/chef/provider/template/content.rb b/lib/chef/provider/template/content.rb
index acf200621d..e47bbd4a7c 100644
--- a/lib/chef/provider/template/content.rb
+++ b/lib/chef/provider/template/content.rb
@@ -36,7 +36,26 @@ class Chef
private
def file_for_provider
- context = TemplateContext.new(new_resource.variables)
+ # Deal with any DelayedEvaluator values in the template variables.
+ visitor = lambda do |obj|
+ case obj
+ when Hash
+ # Avoid mutating hashes in the resource in case we're changing anything.
+ obj.each_with_object(obj.class.new) do |(key, value), memo|
+ memo[key] = visitor.call(value)
+ end
+ when Array
+ # Avoid mutating arrays in the resource in case we're changing anything.
+ obj.map {|value| visitor.call(value) }
+ when DelayedEvaluator
+ new_resource.instance_eval(&obj)
+ else
+ obj
+ end
+ end
+ variables = visitor.call(new_resource.variables)
+
+ context = TemplateContext.new(variables)
context[:node] = run_context.node
context[:template_finder] = template_finder