[chef] Re: Re: 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: Re: Re: more of a ruby problem
  • Date: Wed, 30 Oct 2013 10:27:32 -0700

Thanks Daniel,

The file has dynamic content provided by end users, so i have to read this file,  you mean not to use the ruby_block and put the code directly in the recipe ?
like this , it did not work for me , may be i am doing something wrong

Thanks for your help

-Manoj

cookbook_file "/local_app/#{node[:tcat][:war_name]}.properties" do
  source "#{node[:tcat][:war_name]}.properties"
  mode 0777
  owner "deploy"
  group "deploy"
end


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



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

On Wednesday, October 30, 2013 at 9:41 AM, Manoj Thakkar wrote:

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
Looking at your recipe code, it looks like you read some file, grep the relevant information out of it, and then you want to create chef resources to configure your system based on the contents. So you you take a deeper look. 

Where does this file come from? Is it managed with Chef? If it comes from some other process, then you could read the file directly in the recipe without using a ruby_block resource.

If, on the other hand, you manage this file with Chef, then you should try to pull the relevant data in the file into chef attributes (or a data bag item or whatever). Then you’ll have all the data you’re trying to extract from the file already available in the compile phase of the chef run and you won’t have to parse the file at all.


-- 
Daniel DeLeo





Archive powered by MHonArc 2.6.16.

§