Skip to content

Instantly share code, notes, and snippets.

@ryanycoleman
Created May 30, 2012 21:26
Show Gist options
  • Save ryanycoleman/2839067 to your computer and use it in GitHub Desktop.
Save ryanycoleman/2839067 to your computer and use it in GitHub Desktop.
# Generates facts of the version pkg_foo => 'version'
begin
require 'puppet'
pkgs = Puppet::Type.type(:package).instances
pkgs.each do |pkg|
Facter.add("pkg_#{pkg[:name]}") do
value = pkg.provider.properties[:ensure]
if value != :absent
setcode { value }
end
end
end
rescue => LoadError
Facter.warn 'Unable to load puppet; cannot generate pkg facts.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment