Created
June 8, 2009 13:43
-
-
Save sheldonh/125819 to your computer and use it in GitHub Desktop.
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 characters
| 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