Not able to run command in ruby block


#1

HI, this is what my code looks like , somehow the #{host} below is not
replaced correctly in the grep,

any clues why ?

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

Thanks
Manoj


#2

Your backticks are being evaluatied during the compilation phase of the
chef-client run.
You want this: https://github.com/opscode/mixlib-shellout

-s

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

HI, this is what my code looks like , somehow the #{host} below is not
replaced correctly in the grep,

any clues why ?

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

Thanks
Manoj


#3

He should probably use mixlib-shellout, but the backticks are inside of
the ruby_block’s block so they are evaluated at converge time. Are you
actually sure that it isn’t printing out? You should probably use
Chef::Log.info rather than puts.

Douglas William Thrift
douglaswth@gmail.com
http://douglasthrift.net/

On 10/29/2013 4:50 PM, Sean OMeara wrote:

Your backticks are being evaluatied during the compilation phase of the
chef-client run.
You want this: https://github.com/opscode/mixlib-shellout

-s

On Tue, Oct 29, 2013 at 6:26 PM, Manoj Thakkar <manoj.thakkar@gmail.com
mailto:manoj.thakkar@gmail.com> wrote:

HI, this is what my code looks like , somehow the #{host} below is
not replaced correctly in the grep,

any clues why ? 
 

 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

Thanks
Manoj