Skip to content

Instantly share code, notes, and snippets.

@sheldonh
Created June 8, 2009 13:43
Show Gist options
  • Select an option

  • Save sheldonh/125819 to your computer and use it in GitHub Desktop.

Select an option

Save sheldonh/125819 to your computer and use it in GitHub Desktop.
def hos_server(host, attr)
value = nil
server_block = nil
File.open("/etc/hos_server").each do |line|
line.chomp!
if line =~ /^server:\s+(\S+)\s+\{\s*$/
if host == $1
server_block = host
else
server_block = nil
end
elsif host == server_block and line =~ /^\s*([^:]+):\s*(.*);\s*$/
if attr == $1
value = $2
break
end
end
end
value
end
["antivirus", "backupserver", ...].each do |hos_fact|
Facter.add("hos_#{hos_fact}") do
setcode do
hos_server($fqdn, hos_fact)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment