Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Created September 9, 2016 21:43
Show Gist options
  • Save h0tw1r3/6f0d57f2dd9b09411ca63ce35263d140 to your computer and use it in GitHub Desktop.
Save h0tw1r3/6f0d57f2dd9b09411ca63ce35263d140 to your computer and use it in GitHub Desktop.
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