Created
December 17, 2012 21:08
Revisions
-
srinivasmohan created this gist
Dec 17, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #Rebuild hosts file from knife node list, require 'erb' require 'json' require 'ohai' #to find my own IP def myaddress thissys=Ohai::System.new thissys.all_plugins myip=thissys['cloud']['private_ips'][0] return myip end #This is called in the template file by erb def findremoteip(name=nil) return "#No such name" if name.nil? svrname=name+'.somedomain.com' nodes.search("name:#{svrname}") do |thisnode| return "#{thisnode['cloud']['private_ips'][0]} #{name} #{svrname}" if thisnode['fqdn']==svrname end return "# No nodes entry for "+svrname end template='/etc/hosts.erb' #These are used in the template. scriptname="#{$0} #{$1}" myip_ohai=myaddress abort "Could not find my IP?" if myip_ohai.nil? erb=ERB.new File.new(template).read,nil, '<>' puts erb.result(binding)