Created
September 9, 2016 21:43
-
-
Save h0tw1r3/6f0d57f2dd9b09411ca63ce35263d140 to your computer and use it in GitHub Desktop.
puppet fact for rpm _packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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