Skip to content

Instantly share code, notes, and snippets.

@oliverdaff
Created June 7, 2012 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliverdaff/2885679 to your computer and use it in GitHub Desktop.
Save oliverdaff/2885679 to your computer and use it in GitHub Desktop.
Facter to set facts of versions installed
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