Cody Herriges <gmail at c.a.herriges.com>
Used the ipaddress fact that is already part of Facter as a template.
# File lib/facter/ipaddress6.rb, line 24 def get_address_after_token(output, token, return_first=false) ip = nil output.scan(%r#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match| match = match.first unless match =~ %rfe80.*/ or match == "::1" ip = match break if return_first end end ip end
# File lib/facter/ec2.rb, line 4 def metadata(id = "") open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read. split("\n").each do |o| key = "#{id}#{o.gsub(/\=.*$/, '/')}" if key[-1..-1] != '/' value = open("http://169.254.169.254/2008-02-01/meta-data/#{key}").read. split("\n") symbol = "ec2_#{key.gsub(/\-|\//, '_')}".to_sym Facter.add(symbol) { setcode { value.join(',') } } else metadata(key) end end end
This supports the fact that the selinux mount point is not always in the same location – the selinux mount point is operating system specific.
# File lib/facter/selinux.rb, line 17 def selinux_mount_point if FileTest.exists?('/proc/self/mountinfo') File.open('/proc/self/mountinfo') do |f| f.grep(%rselinuxfs/) do |line| line.split[4] end end else "/selinux" end end
# File lib/facter/ec2.rb, line 19 def userdata() begin value = open("http://169.254.169.254/2008-02-01/user-data/").read.split Facter.add(:ec2_userdata) { setcode { value } } rescue OpenURI::HTTPError end end