Sean brought this up in your previous thread but it’s most likely due to the back ticks being evaluated during the compile phase versus the run phase. Use Chef::Log.info to output debugging information and avoid shelling out in favor of Mixlib::ShellOut. Also, you can get the node hostname through node[:fqdn].host = node[:fqdn]Chef::Log.info "Hostname is #{node[:fqdn]}"File.open("/local_app/account-rest.properties", "r").each_line do |line|Chef::Log.debug "#{host} Account Rest line: #{line}"if line.include?(host)Chef::Log.info "Found host #{host} in #{line}"account_value = line.split(':').lastChef::Log.info "Found account value #{account_value}"endendOn Tuesday, October 29, 2013 at 10:51 PM, Manoj Thakkar wrote:
Hi All,i have written this code but it never goes in if condition , i ma not sure why ,if i replace the host with the real value of the hostname -s it does work , i am not sure what the issue is ,might be a syntax error but Ruby does not complain about it , it silently ignores the if conditionplease advise.host=`hostname -s`puts " hostname is #{host}"File.open("/local_app/account-rest.properties", "r").each_line do |line|puts lineputs hostline.chompif line.include? "host"puts " found host #{line}"value = line.split(":").lastputs " found account value #{value}"puts valueendend
Archive powered by MHonArc 2.6.16.