Skip to content

Instantly share code, notes, and snippets.

@juliandunn

juliandunn/packages.rb

Last active Aug 29, 2015
Embed
What would you like to do?
Refactored version of Chef RPM packages plugin; also expanded to handle dpkgs. Original source code: https://github.com/demonccc/chef-repo/blob/master/plugins/ohai/linux/rpm.rb
#
# Author:: Claudio Cesar Sanchez Tejeda <demonccc@gmail.com>
# Author:: Julian C. Dunn <jdunn@chef.io>
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
# limitations under the License.
#
Ohai.plugin(:Packages) do
provides "linux/packages"
depends "platform"
collect_data(:default) do
packages Mash.new
if %w{ rhel fedora suse }.include?(platform_family) or %w{ redhat fedora centos suse }.include?(platform)
so = shell_out("rpm -qa --queryformat '%{NAME} %{VERSION} %{RELEASE}\n'")
so.stdout.lines do |line|
fields = line.split(/\s+/)
packages[fields[0]] = { 'version' => fields[1], 'release' => fields[2] }
end
elsif %w{ debian }.include?(platform_family)
so = shell_out("dpkg-query -W -f='${Package} ${Version}\n'")
so.stdout.lines do |line|
fields = line.split(/\s+/)
packages[fields[0]] = { 'version' => fields[1] }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment