Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
puppet fact for rpm _packages
require 'facter'
def hash_tree
Hash.new do |hash, key|
hash[key] = hash_tree
end
end
Facter.add(:packages) do
confine :osfamily => 'Redhat'
setcode do
package_data = Facter::Util::Resolution::exec('rpm --query --all --qf "%{NAME}||%{VERSION}\n"')
@packages = hash_tree
package_data.split("\n").each do |line|
package_name, package_version = line.split("||")
@packages[package_name] = package_version
end
@packages
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment