[chef] Re: Re: Re: Re: Re: Re: more of a ruby problem


Chronological Thread 
  • From: Manoj Thakkar < >
  • To: " " < >
  • Subject: [chef] Re: Re: Re: Re: Re: Re: more of a ruby problem
  • Date: Wed, 30 Oct 2013 09:41:08 -0700

Thanks Daniel,

What i am trying to achieve is set an array of strings as an attribute or variable inside the ruby block and then use it outside in various chef resource,

How do i do that ? please advise.

Thanks
Manoj



On Wed, Oct 30, 2013 at 8:55 AM, Daniel DeLeo < " target="_blank"> > wrote:

On Wednesday, October 30, 2013 at 1:16 AM, Manoj Thakkar wrote:

Sorry for asking it , but i am stuck again , looks like i am not able to read the variable i got from ruby_block

i am not sure what's wrong :


ruby_block "acc-deploy-host" do
block do
Chef::Log.info " host name is #{node['hostname']} "
host=node['hostname']
puts " hostname is #{host}"

File.open("/local_app/account-rest.properties", "r").each_line do |line|
Chef::Log.info "#{host} Account Rest line: #{line}"
  if line.include?(host)
    Chef::Log.info "Found host #{host} in #{line}"
    deploy = line.split(':').last
    deploy = deploy.gsub(/\n/," ")
    node.set['account_deploy']=deploy
    Chef::Log.info "Found account value #{node['account_deploy']}"
end
end
end

node['account_deploy'].each do |x|

puts #x

end
end
An important thing to keep in mind about Ruby blocks is that it may or may not be executed at a different time than the surrounding code. In this case, Chef holds on to the code you pass into `block do` so it can evaluate it during the converge phase of the chef run. The surrounding code is executed immediately.


-- 
Daniel DeLeo
 




Archive powered by MHonArc 2.6.16.

§