Skip to content

Instantly share code, notes, and snippets.

@kenyon
Last active February 9, 2023 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenyon/ac66188dc704951fbacd3a978e0c9f44 to your computer and use it in GitHub Desktop.
Save kenyon/ac66188dc704951fbacd3a978e0c9f44 to your computer and use it in GitHub Desktop.
# 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
@vegaaz
Copy link

vegaaz commented Feb 9, 2023

lol I just wanted to create a very similar custom fact. Thanks for this! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment