Last active
February 9, 2023 14:12
-
-
Save kenyon/ac66188dc704951fbacd3a978e0c9f44 to your computer and use it in GitHub Desktop.
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
# Puppet Facter custom fact. Return a list of packages installed on | |
# the system as a hash, mapping the package name to the version. | |
# © 2018 Kenyon Ralph | |
# SPDX-License-Identifier: GPL-3.0-or-later | |
Facter.add(:packages) do | |
setcode do | |
packages = {} | |
case Facter.value(:os)['family'] | |
when 'Debian' | |
pkglist = Facter::Core::Execution.execute("dpkg-query --show --showformat='${Package} ${Version}\n'") | |
when 'RedHat' | |
pkglist = Facter::Core::Execution.execute("rpm --query --all --queryformat='%{name} %{version}\n'") | |
end | |
pkglist.each_line do |line| | |
packages[line.split()[0]] = line.split()[1] | |
end | |
packages | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lol I just wanted to create a very similar custom fact. Thanks for this! :)