{"id":430,"date":"2008-06-16T11:47:31","date_gmt":"2008-06-16T10:47:31","guid":{"rendered":"http:\/\/wp.devco.net\/?p=430"},"modified":"2009-10-10T12:39:52","modified_gmt":"2009-10-10T11:39:52","slug":"rework_of_puppet_facts_for_etcfactstxt","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2008\/06\/16\/rework_of_puppet_facts_for_etcfactstxt.php","title":{"rendered":"Rework of puppet facts for \/etc\/facts.txt"},"content":{"rendered":"

Previously I blogged a custom fact<\/a> 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:<\/p>\n


<\/pre>\n

if File.exists?(“\/etc\/facts.txt”)
   File.open(“\/etc\/facts.txt”).each do |line|
      var = nil
      value = nil <\/p>\n

      var = $1 and val = $2 if line =~ \/^(.+)=(.+)$\/<\/p>\n

      if var != nil && val != nil
         Facter.add(var) do
            setcode { val }
         end
      end
   end
end <\/p><\/blockquote>\n

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<\/i> must be a reserved word or something, so now the code is much cleaner.<\/p>\n

<\/pre>\n","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[7],"tags":[121,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/430"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=430"}],"version-history":[{"count":2,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/430\/revisions"}],"predecessor-version":[{"id":1037,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/430\/revisions\/1037"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}