Hi,

> All that being said, if its just one or two packages you care about you can
> simply add a fact for the package versions, but this fact will only show the 
> version on the next puppet run not the one during which you install said 
> package
> since the compile stage of the puppet run is happening on the master prior to
> installing the package.

Merely from an 'inventory' point of view, I felt the need to have facts
for reporting versions of installed packages. I wrote the following code,
that creates facts for package versions, based on a file that lists the
packages I am interested in on a particular server. This file can, of
course, be managed by puppet.

martijn:puppet> cat modules/common/lib/facter/package_versions.rb
require 'puppet'

package_list = "/etc/facter/package_versions_list"

if File.exist?(package_list)
  File.readlines(package_list).each do |l|
    l.strip!

    @pname = ""
    l.split.each do |p|
      if @pname.eql? ""
        @pname = p
      end
      pkg = Puppet::Type.type(:package).new(:name => p)
      v = pkg.retrieve[pkg.property(:ensure)].to_s
      if !v.eql? "purged" and !v.eql? "absent"
        Facter.add("pkg_" + @pname + "_version") do
          setcode do
            v
          end
        end
      end
    end
  end
end



martijn@server002:~> cat /etc/facter/package_versions_list
postgresql
php5-common
mysql-server mysql-server-5.1 mysql-server-5.0


Regards,
Martijn.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to