Thanks a lot for the help Daniel,it worked , i used node.hostname as you suggested and it provided me the value i was looking for, Thanks a lot for the help,its been troubling me from last 3-4 hours now, i am not using Mixlib Shell out rather i wrote ruby_block and ruby for this, i hope thats the right way to do it,all this time this host.chomp was the issue.Thanks again everyone for the helpManoj
On Tue, Oct 29, 2013 at 11:23 PM, Daniel Condomitti < " target="_blank"> > wrote:
If you can’t use node[:fqdn] due to it including the rest of the node’s hostname then you need to call .chomp on the output from ShellOut.run_command:Otherwise you’ll never match that ‘account-rest.properties’ file since it contains “pdevecsas300:acc1” and not “pdevecsas300\n:acc1”. I’d really recommend leveraging as much of chef’s helpers like node attributes and Ruby classes (File, Dir) as possible instead of shelling out. Look at node.hostname, it may return the result you’re looking for without shelling out; otherwise, use node.hostname.split(‘.’).first so you just get the first part of the hostname that’s contained in the file you’re loading.chef > Mixlib::ShellOut.new('hostname -s').run_command.stdout=> "disrupt\n”
On Tuesday, October 29, 2013 at 11:13 PM, Manoj Thakkar wrote:
Thanks Daniel,but i always get the value of hostname when i run my chef client( even the MixLIb shell out did not fix the issue ) , also i want only the hostname not the fullyqualified hostname so unfortunately i can not use fqdn :(hostc=Mixlib::ShellOut.new("hostname -s")hostc.run_commandhost=hostc.stdouthostp=`hostname -s`Chef::Log.info " host name is #{hostp} "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}"logs below ::Recipe: base_tomcat::default.new* ruby_block[acc-deploy-host] action run[2013-10-29T23:09:36-07:00] INFO: Processing ruby_block[acc-deploy-host] action run (base_tomcat::default.new line 9)[2013-10-29T23:09:36-07:00] INFO: host name is pdevecsas300hostname is pdevecsas300pbldejksu300:acc1,acc2pdevecsas300pdevecsas300:acc1,acc2pdevecsas300On Tue, Oct 29, 2013 at 11:04 PM, Daniel Condomitti < " target="_blank"> > wrote: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.