Some people use the node.run_state hash to store stuff like this in.
Why must you modify the scope-local variable in the ruby block?
--AJ
On 23 June 2012 15:56, Adam Jacob < "> > wrote:
> The issue here is that Chef builds a collection of resources, which it
> then iterates over. The block in the ruby block is not evaluated until
> much later. What exactly are you trying to accomplish?
>
> Adam
>
> On Fri, Jun 22, 2012 at 3:04 PM, Daniel S. Kim < "> > wrote:
>> Hello all,
>>
>> I am having hard time with a variable modification. See the snippet below:
>>
>> subdir = ""
>>
>> ruby_block "read target archive directory name" do
>> block do
>> Dir.foreach("/snapshot/#{dbSnapshotId}") do |f|
>> unless(f.to_s.eql? ".")
>> unless (f.to_s.eql? "..")
>> Chef::Log.info("Timestamp: " + f.to_s)
>> subdir = f.to_s
>> node[:RestoreSubdir] = subdir
>> node.save
>> end
>> end
>> end
>> end
>> action :create
>> end
>>
>>
>> After the ruby_block, subdir is still an empty string. However, Chef::Log
>> shows a value otherwise. I also tried these other method in order to get
>> this String outside the ruby_block scope:
>> 1. script resource => variable modification undone once out of scope
>> 2. ruby_block resource => variable modification undone once out of scope
>> 3. separate recipe with ruby code => ruby code still runs 1st before
>> mounting the drive
>> 4. separate recipe with ruby_block/script => still cannot see the variable
>> modification once out of scope
>> 5. node.save within ruby_block => save doesn't occur until chef-client is
>> done running all the resources
>> 6. databag.save within ruby_block => save doesn't occur until chef-client is
>> done running all the resources
>>
>>
>> Any suggestion?
>>
>>
>>
>>
>> Regard,
>>
>> --
>> Daniel S. Kim
>>
>
>
>
> --
> Opscode, Inc.
> Adam Jacob, Chief Customer Officer
> T: (206) 619-7151 E: ">
Archive powered by MHonArc 2.6.16.