ody/pkginventory problem / How do _you_ get a listing of all packages installed on a system?

93 views
Skip to first unread message

Stack Kororā

unread,
Jan 23, 2014, 11:54:45 PM1/23/14
to puppet...@googlegroups.com
Greetings,

I am using ody/pkginventory [http://forge.puppetlabs.com/ody/pkginventory] as a way of getting information about what rpms are installed on a system. I am using this module over `puppet resource package` for two reasons: 1) Having it as a fact helps some of the other things we are doing and I don't know if-it's-possible/how to get the results of a `puppet resource package` as a fact and 2) I can't seem to figure out how to query the puppetmaster puppetdb (using curl) and pull back a full listing of installed packages on a node but I _can_ get the facts this way. 

We made a few small modifications to this package to add the Scientific and SLES OS's (which both OS's work just fine; just need to make the change in both pkg.rb files) and rolled out this module to our dev environment. That is when I noticed a "problem". I realize I can get the "kernel" fact, I am just using the "kernel" package as an example as it is reproducible on many systems. The information I am really after is other packages which have the same problem.

$ uname -r
2.6.32-431.1.2.el6.x86_64
$ facter -p | grep "pkg_kernel "
pkg_kernel => 2.6.32-358.el6
$ puppet resource package kernel
package { 'kernel':
  ensure => '2.6.32-358.el6',
}
$ rpm -qa | grep "^kernel-2"
kernel-2.6.32-358.el6.x86_64
kernel-2.6.32-431.1.2.el6.x86_64

The problem is that neither the resource nor the module are returning the actual running kernel. In reality, I would like to know every package. My co-worker (who is a bit more familiar with Ruby then I am) made the following changes to lib/facter/pkg.rb:

require 'facter/util/pkg'
counter_hash = {}
Facter::Util::Pkg.package_list.each do |key, value|
  if counter_hash[:"#{key}"].nil?
    counter_hash[:"#{key}"] = value
  else
    counter_hash[:"#{key}"] << ", #{value}"
  end
end
counter_hash.each do |key, value|
  Facter.add(:"pkg_#{key}") { setcode { value } } end


This produces an output of : pkg_kernel => 2.6.32-358.el6, 2.6.32-431.1.2.el6 Much more desirable. So the question for this group is, before I roll this out to all my system does anyone have a better solution or suggestion on accomplishing this task?

What I have after my co-workers mod works, but I am really curious how/if others are retrieving a list of all packages installed on a system.

Thanks!

Andrew

unread,
Jan 29, 2014, 11:56:27 PM1/29/14
to puppet...@googlegroups.com
# every package, name only.
rpm -qa --queryformat="%{NAME}\n"

# or more info ...
rpm -qa --queryformat="%{NAME} - %{VERSION} - %{ARCH}\n"

Hi Stack,

have you tried 

package { "kernel.$architecture":
  ensure => '2.6.32-358.el6',
}

to make sure it doesnt find the i686 version as well ?

Also note that a reboot is required for a newly installed kernel version to become the running version,
Also note that yum will keep upto 2 older versions of the kernel installed as recovery boot options in the grub kernel, so there is always more than one kernel-version present on the system.



Stack Kororā

unread,
Jan 30, 2014, 6:59:03 AM1/30/14
to puppet...@googlegroups.com
Greetings,
Thanks for the response.

The pkginventory is already doing this inside of util/pkg.rb:
rpm -qa --qf %{NAME}"\t"%{VERSION}-%{RELEASE}

I am fully aware of how multiple kernels work. As stated, the kernel was just an example. I need/want every package installed returned to me and the version of the pkginventory code currently listed in the forge is nondeterministic on what package version is returned when multiple versions exist. This is the problem for me.

We have been running our mods in production for a few days now and things are running well.

Thanks!
Reply all
Reply to author
Forward
0 new messages