Created
June 7, 2012 00:16
-
-
Save oliverdaff/2885679 to your computer and use it in GitHub Desktop.
Facter to set facts of versions installed
This file contains 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
require 'puppet' | |
require 'puppet/application' | |
require 'facter' | |
typeobj = Puppet::Type.type("package") | |
properties = typeobj.properties.collect { |s| s.name } | |
format = proc {|trans| | |
trans.dup.collect do |param, value| | |
if value.nil? or value.to_s.empty? | |
trans.delete(param) | |
elsif value.to_s == "absent" and param.to_s != "ensure" | |
trans.delete(param) | |
end | |
unless properties.include?(param) | |
trans.delete(param) | |
end | |
end | |
Facter.add(trans.name) do | |
setcode do | |
trans.to_hash[:ensure] | |
end | |
end | |
} | |
values = typeobj.instances.collect do |obj| | |
trans = obj.to_trans(true) | |
format.call(trans) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment