Thanks Josiah,what is it i have to do to make it an array of strings ? the values are comma separated so its an array essentially.ThanksManojOn Wed, Oct 30, 2013 at 11:57 AM, Josiah Kiehl < " target="_blank"> > wrote:
No, it's definitely a string you're assigning, not an array.# #split returns an array of strings. #last returns the last string in the array. deploy is currently a stringdeploy = line.split(':').last# You are doing a gsub on a string, so deploy is still a string. As an aside, you could use #gsub! here to avoid the extra assignment.deploy = deploy.gsub(/\n/," ")# node['account_deploy'] is being assigned to deploy which is a stringnode.set['account_deploy']=deployWhat is unclear? The string happens to be %q["acc1","acc2"], which looks like an array in the logs, but you can see in your logs that the " are escaped, so you do in fact have a string.On Wed, Oct 30, 2013 at 11:21 AM, Manoj Thakkar < " target="_blank"> > wrote:
Thanks Doug,but i see the value of the node attribute though in the logs ,Chef Client failed. 0 resources updated[2013-10-30T01:45:07-07:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out[2013-10-30T01:45:07-07:00] FATAL: NoMethodError: undefined method `each' for "\"acc1\",\"acc2\" ":Stringlooks like its getting the value but not treating it as an array of strings or something.ThanksManojOn Wed, Oct 30, 2013 at 11:03 AM, Douglas Thrift < " target="_blank"> > wrote:
That doesn't work because the ruby_block's block doesn't execute until
converge time and the loop you have there that is outside of the
ruby_block runs at compile time.
Douglas William Thrift
< " target="_blank"> >
<http://douglasthrift.net/>
> *logs :*
On 10/30/2013 1:47 AM, Manoj Thakkar wrote:
>
> 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 please advise
>
> Here is the code i am writing:
>
> 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
>
>
> properties file data :
>
> pbldejksu300:'acc1','acc2'
> pdevecsas300:'acc1','acc2'
>
>
> Cookbook Trace:
> ---------------
> /var/chef/cache/cookbooks/base_tomcat/recipes/new.rb:26:in `block in
> from_file'
> /var/chef/cache/cookbooks/base_tomcat/recipes/new.rb:9:in `from_file'
>
>
>
> [2013-10-30T01:45:07-07:00] ERROR: Running exception handlers
> [2013-10-30T01:45:07-07:00] FATAL: Saving node information to
> /var/chef/cache/failed-run-data.json
> [2013-10-30T01:45:07-07:00] ERROR: Exception handlers complete
> Chef Client failed. 0 resources updated
> [2013-10-30T01:45:07-07:00] FATAL: Stacktrace dumped to
> /var/chef/cache/chef-stacktrace.out
> [2013-10-30T01:45:07-07:00] FATAL: NoMethodError: undefined method
> `each' for "\"acc1\",\"acc2\" ":String
Archive powered by MHonArc 2.6.16.