Simple read a variable issue


#1

Hey,

i have been trying to fix this for almost 30 minutes now , thought i shall
better ask, please looks at the code snippet below, I am not able to
access this simple variable what am i doing wrong ? please advise.

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.default[“acc-deploy”] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
*node[:acc_deploy].each do |x| ----- this does not work *
puts #x

end


#2

i changed the code to this ,

still does not work , what is wrong ?

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[‘acc_deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:17 PM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

Hey,

i have been trying to fix this for almost 30 minutes now , thought i shall
better ask, please looks at the code snippet below, I am not able to
access this simple variable what am i doing wrong ? please advise.

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.default[“acc-deploy”] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
*node[:acc_deploy].each do |x| ----- this does not work *
puts #x

end


#3

In the first case you use a dash node.set[:acc-deploy]
*
In the second case you are using underscore
**node[‘acc_deploy’].each *
*
*
Additionally I would recommend standardizing on symbols vs strings

Hopefully that works.

On Tue, Oct 29, 2013 at 4:27 PM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

i changed the code to this ,

still does not work , what is wrong ?

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[‘acc_deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:17 PM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

Hey,

i have been trying to fix this for almost 30 minutes now , thought i
shall better ask, please looks at the code snippet below, I am not able to
access this simple variable what am i doing wrong ? please advise.

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.default[“acc-deploy”] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
*node[:acc_deploy].each do |x| ----- this does not work *
puts #x

end


#4

Thanks Andrew,

i pasted the wrong code , i fixed that _ vs “-” thing , but it still did
not work ,same error

Chef Client failed. 0 resources updated
[2013-10-29T13:36:43-07:00] FATAL: Stacktrace dumped to
/var/chef/cache/chef-stacktrace.out
[2013-10-29T13:36:43-07:00] FATAL: NoMethodError: undefined method `each’
for nil:NilClass
You have mail in /var/spool/mail/deploy

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do

host=hostname -s
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[:acc-deploy]}"
end
action :create
end
node[‘acc-deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:32 PM, Andrew Gross andrew@yipit.com wrote:

In the first case you use a dash node.set[:acc-deploy]
*
In the second case you are using underscore
**node[‘acc_deploy’].each *
*
*
Additionally I would recommend standardizing on symbols vs strings

Hopefully that works.

On Tue, Oct 29, 2013 at 4:27 PM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

i changed the code to this ,

still does not work , what is wrong ?

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[‘acc_deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:17 PM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

Hey,

i have been trying to fix this for almost 30 minutes now , thought i
shall better ask, please looks at the code snippet below, I am not able to
access this simple variable what am i doing wrong ? please advise.

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.default[“acc-deploy”] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
*node[:acc_deploy].each do |x| ----- this does not work *
puts #x

end


#5

Try using strings in both node.set[‘acc-deploy’] and node[‘acc-deploy’]
instead of symbols like :acc-deploy

On Tue, Oct 29, 2013 at 4:38 PM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

Thanks Andrew,

i pasted the wrong code , i fixed that _ vs “-” thing , but it still did
not work ,same error

Chef Client failed. 0 resources updated
[2013-10-29T13:36:43-07:00] FATAL: Stacktrace dumped to
/var/chef/cache/chef-stacktrace.out
[2013-10-29T13:36:43-07:00] FATAL: NoMethodError: undefined method `each’
for nil:NilClass
You have mail in /var/spool/mail/deploy

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do

host=hostname -s
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[:acc-deploy]}"
end
action :create
end
node[‘acc-deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:32 PM, Andrew Gross andrew@yipit.com wrote:

In the first case you use a dash node.set[:acc-deploy]
*
In the second case you are using underscore
**node[‘acc_deploy’].each *
*
*
Additionally I would recommend standardizing on symbols vs strings

Hopefully that works.

On Tue, Oct 29, 2013 at 4:27 PM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

i changed the code to this ,

still does not work , what is wrong ?

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[‘acc_deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:17 PM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

Hey,

i have been trying to fix this for almost 30 minutes now , thought i
shall better ask, please looks at the code snippet below, I am not able to
access this simple variable what am i doing wrong ? please advise.

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.default[“acc-deploy”] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
*node[:acc_deploy].each do |x| ----- this does not work *
puts #x

end


#6

Dashes are not valid in symbol names unless you quote them. It’s interpreted as :acc - deploy. Just switch to underscores and you’ll be good.

On Tuesday, October 29, 2013 at 1:38 PM, Manoj Thakkar wrote:

Thanks Andrew,

i pasted the wrong code , i fixed that _ vs “-” thing , but it still did not work ,same error

Chef Client failed. 0 resources updated
[2013-10-29T13:36:43-07:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-10-29T13:36:43-07:00] FATAL: NoMethodError: undefined method `each’ for nil:NilClass
You have mail in /var/spool/mail/deploy

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do

host=hostname -s
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[:acc-deploy]}"
end
action :create
end
node[‘acc-deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:32 PM, Andrew Gross <andrew@yipit.com (mailto:andrew@yipit.com)> wrote:

In the first case you use a dash node.set[:acc-deploy]
In the second case you are using underscore node[‘acc_deploy’].each

Additionally I would recommend standardizing on symbols vs strings

Hopefully that works.

On Tue, Oct 29, 2013 at 4:27 PM, Manoj Thakkar <manoj.thakkar@gmail.com (mailto:manoj.thakkar@gmail.com)> wrote:

i changed the code to this ,

still does not work , what is wrong ?

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do

node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[‘acc_deploy’].each do |x|

puts #x

end

On Tue, Oct 29, 2013 at 1:17 PM, Manoj Thakkar <manoj.thakkar@gmail.com (mailto:manoj.thakkar@gmail.com)> wrote:

Hey,

i have been trying to fix this for almost 30 minutes now , thought i shall better ask, please looks at the code snippet below, I am not able to access this simple variable what am i doing wrong ? please advise.

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.default[“acc-deploy”] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[:acc_deploy].each do |x| ----- this does not work
puts #x

end


#7

Thanks Daniel,

its good to know that - in not allowed in symbol.

i still get the same error though

ruby_block “acc-deploy-host” do
block do
host=hostname -s
node.set[:acc_deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[‘acc_deploy’]}"
end
end
node[‘acc_deploy’].each do |x|
puts #x

end

/var/chef/cache/cookbooks/base_tomcat/recipes/default.new.rb:

9: ruby_block “acc-deploy-host” do
10: block do
11: host=hostname -s
12: node.set[:acc_deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
13: puts "value is #{node[‘acc_deploy’]}"
14: end
15: end
16>> node[‘acc_deploy’].each do |x|
17: puts #x
18:
19: end
20:

[2013-10-29T13:55:58-07:00] ERROR: Running exception handlers
[2013-10-29T13:55:58-07:00] FATAL: Saving node information to
/var/chef/cache/failed-run-data.json
[2013-10-29T13:55:58-07:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-10-29T13:55:58-07:00] FATAL: Stacktrace dumped to
/var/chef/cache/chef-stacktrace.out
[2013-10-29T13:55:58-07:00] FATAL: NoMethodError: undefined method `each’
for nil:NilClass

On Tue, Oct 29, 2013 at 1:52 PM, Daniel Condomitti daniel@condomitti.comwrote:

Dashes are not valid in symbol names unless you quote them. It’s
interpreted as :acc - deploy. Just switch to underscores and you’ll be
good.

On Tuesday, October 29, 2013 at 1:38 PM, Manoj Thakkar wrote:

Thanks Andrew,

i pasted the wrong code , i fixed that _ vs “-” thing , but it still did
not work ,same error

Chef Client failed. 0 resources updated
[2013-10-29T13:36:43-07:00] FATAL: Stacktrace dumped to
/var/chef/cache/chef-stacktrace.out
[2013-10-29T13:36:43-07:00] FATAL: NoMethodError: undefined method
`each’ for nil:NilClass
You have mail in /var/spool/mail/deploy

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do

host=hostname -s
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[:acc-deploy]}"
end
action :create
end
node[‘acc-deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:32 PM, Andrew Gross <andrew@yipit.com (mailto:
andrew@yipit.com)> wrote:

In the first case you use a dash node.set[:acc-deploy]
In the second case you are using underscore node[‘acc_deploy’].each

Additionally I would recommend standardizing on symbols vs strings

Hopefully that works.

On Tue, Oct 29, 2013 at 4:27 PM, Manoj Thakkar <
manoj.thakkar@gmail.com (mailto:manoj.thakkar@gmail.com)> wrote:

i changed the code to this ,

still does not work , what is wrong ?

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do

node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2

puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[‘acc_deploy’].each do |x|

puts #x

end

On Tue, Oct 29, 2013 at 1:17 PM, Manoj Thakkar <
manoj.thakkar@gmail.com (mailto:manoj.thakkar@gmail.com)> wrote:

Hey,

i have been trying to fix this for almost 30 minutes now , thought
i shall better ask, please looks at the code snippet below, I am not able
to access this simple variable what am i doing wrong ? please advise.

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.default[“acc-deploy”] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2

puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[:acc_deploy].each do |x| ----- this does not work
puts #x

end


#8

I’m not entirely sure why that isn’t working but it could be due to that the node.set isn’t actually updating the node object until it’s outside of that ruby block. Change the node attribute access to either all strings or all symbols. Normally you can use strings and symbols interchangeably though you should use one consistently:

chef > n.set[:blah] = ‘test’
=> "test"
chef > n[:blah]
=> “test"
chef > n[‘blah’]
=> “test”

On Tuesday, October 29, 2013 at 1:57 PM, Manoj Thakkar wrote:

Thanks Daniel,

its good to know that - in not allowed in symbol.

i still get the same error though

ruby_block “acc-deploy-host” do
block do
host=hostname -s
node.set[:acc_deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[‘acc_deploy’]}"
end
end
node[‘acc_deploy’].each do |x|
puts #x

end

/var/chef/cache/cookbooks/base_tomcat/recipes/default.new.rb:

9: ruby_block “acc-deploy-host” do
10: block do
11: host=hostname -s
12: node.set[:acc_deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
13: puts "value is #{node[‘acc_deploy’]}"
14: end
15: end
16>> node[‘acc_deploy’].each do |x|
17: puts #x
18:
19: end
20:

[2013-10-29T13:55:58-07:00] ERROR: Running exception handlers
[2013-10-29T13:55:58-07:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-10-29T13:55:58-07:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-10-29T13:55:58-07:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-10-29T13:55:58-07:00] FATAL: NoMethodError: undefined method `each’ for nil:NilClass

On Tue, Oct 29, 2013 at 1:52 PM, Daniel Condomitti <daniel@condomitti.com (mailto:daniel@condomitti.com)> wrote:

Dashes are not valid in symbol names unless you quote them. It’s interpreted as :acc - deploy. Just switch to underscores and you’ll be good.

On Tuesday, October 29, 2013 at 1:38 PM, Manoj Thakkar wrote:

Thanks Andrew,

i pasted the wrong code , i fixed that _ vs “-” thing , but it still did not work ,same error

Chef Client failed. 0 resources updated
[2013-10-29T13:36:43-07:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-10-29T13:36:43-07:00] FATAL: NoMethodError: undefined method `each’ for nil:NilClass
You have mail in /var/spool/mail/deploy

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do

host=hostname -s
node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[:acc-deploy]}"
end
action :create
end
node[‘acc-deploy’].each do |x|
puts #x

end

On Tue, Oct 29, 2013 at 1:32 PM, Andrew Gross <andrew@yipit.com (mailto:andrew@yipit.com) (mailto:andrew@yipit.com)> wrote:

In the first case you use a dash node.set[:acc-deploy]
In the second case you are using underscore node[‘acc_deploy’].each

Additionally I would recommend standardizing on symbols vs strings

Hopefully that works.

On Tue, Oct 29, 2013 at 4:27 PM, Manoj Thakkar <manoj.thakkar@gmail.com (mailto:manoj.thakkar@gmail.com) (mailto:manoj.thakkar@gmail.com)> wrote:

i changed the code to this ,

still does not work , what is wrong ?

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do

node.set[:acc-deploy] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[‘acc_deploy’].each do |x|

puts #x

end

On Tue, Oct 29, 2013 at 1:17 PM, Manoj Thakkar <manoj.thakkar@gmail.com (mailto:manoj.thakkar@gmail.com) (mailto:manoj.thakkar@gmail.com)> wrote:

Hey,

i have been trying to fix this for almost 30 minutes now , thought i shall better ask, please looks at the code snippet below, I am not able to access this simple variable what am i doing wrong ? please advise.

cookbook_file “/local_app/account-rest.properties” do
source "account-rest.properties"
mode 0777
owner "deploy"
group "deploy"
end
ruby_block “acc-deploy-host” do
block do
node.default[“acc-deploy”] = cat /local_app/account-rest.properties | grep -i "#{host}" | cut -d":" -f2
puts "value is #{node[“acc-deploy”]}"
end
action :create
end
node[:acc_deploy].each do |x| ----- this does not work
puts #x

end