Forcing parameter to resource to be elevated at execute phase


#1

hi everyone,

i was wondering if variable passed as parameter to resource can be made to be
elevated at execute phase instead of compile phase. I have the following code
example.

ruby_block “Calculate secret” do
block do
node.set[‘secret_message’] = "This is a secret"
end
end

file “/tmp/test” do
content "#{node[‘secret_message’]}"
mode 0644
end

This is a simplified version of the challenge i have, what i want is for the
file resource to use a variable node[‘secret_message’] which is computed by the
ruby_block resource. but the end result is the file /tmp/test contains nothing
because #{node[‘secret_message’]} being ruby code is elevated before the
ruby_block resource is run.

Does anyone know a solution? if there is a blog post somewhere let me know.

Thanks


#2

We were thinking about hacking this up today, supporting converge-time
evaluation of any parameter by wrapping it in a proc or something… Seems
legit.

Thoughts?

AJ

On 21 December 2012 06:40, Chao chaoranxie@gmail.com wrote:

hi everyone,

i was wondering if variable passed as parameter to resource can be made to
be
elevated at execute phase instead of compile phase. I have the following
code
example.

ruby_block “Calculate secret” do
block do
node.set[‘secret_message’] = "This is a secret"
end
end

file “/tmp/test” do
content "#{node[‘secret_message’]}"
mode 0644
end

This is a simplified version of the challenge i have, what i want is for
the
file resource to use a variable node[‘secret_message’] which is computed
by the
ruby_block resource. but the end result is the file /tmp/test contains
nothing
because #{node[‘secret_message’]} being ruby code is elevated before the
ruby_block resource is run.

Does anyone know a solution? if there is a blog post somewhere let me
know.

Thanks


#3

On Thursday, December 20, 2012 at 3:52 PM, AJ Christensen wrote:

We were thinking about hacking this up today, supporting converge-time evaluation of any parameter by wrapping it in a proc or something… Seems legit.

Thoughts?

AJ
We discussed this at Wednesday’s code review. The only major concern with this approach is that validation of resource parameters should also apply to lazily evaluated arguments. We think this can be accomplished by hacking set_or_return. We left some comments about the various approaches we discussed on this ticket:

http://tickets.opscode.com/browse/CHEF-1814

Cheers,


Daniel DeLeo