Rework of puppet facts for /etc/facts.txt

Previously I blogged a custom fact that reads /etc/facts.txt to build up some custom facts for use in Puppet manifests, well I've since learned a thing or two about Ruby and have improved the code, new code below:

if File.exists?("/etc/facts.txt")
File.open("/etc/facts.txt").each do |line|
var = nil
value = nil

var = $1 and val = $2 if line =~ /^(.+)=(.+)$/

if var != nil && val != nil
Facter.add(var) do
setcode { val }
end
end
end
end

As I mentioned previously I knew the code was horrible and had a whole redundant loop in it but couldn't get it going otherwise.  The big change is in choice of variable names to use inside the setcode, sees value must be a reserved word or something, so now the code is much cleaner.


                                    

Leave a comment

Recent Entries

  • flashpolicyd 2.0

    I wrote a multi threaded server for Adobe Flash Policy requests, some background from Adobe:Since policy files were first introduced, Flash Player has recognized /crossdomain.xml...

  • Adventures with Ruby

    Some more about my continuing experiences with ruby, in my last post I saidthe language does what you'd expect and as you'll see in my...

  • New programming language of choice - Ruby

    I have fallen out of love with Perl some time ago, I cannot point to one specific thing about it that put me off, I...

  • On working from home

    I've not been posting much here, work has been incredibly manic the last while, especially I need to still finish off my SSO posts with...

  • Rework of puppet facts for /etc/facts.txt

    Previously I blogged a custom fact that reads /etc/facts.txt to build up some custom facts for use in Puppet manifests, well I've since learned a...

Close