Skip to content

Instantly share code, notes, and snippets.

@oliverdaff
Created June 7, 2012 00:16
Show Gist options
  • Save oliverdaff/2885679 to your computer and use it in GitHub Desktop.
Save oliverdaff/2885679 to your computer and use it in GitHub Desktop.

Revisions

  1. oliverdaff created this gist Jun 7, 2012.
    28 changes: 28 additions & 0 deletions packagefacts.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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