Check version of installed RPM

3,168 views
Skip to first unread message

Jonathan Gazeley

unread,
Jan 24, 2011, 8:07:27 AM1/24/11
to puppet...@googlegroups.com
Hi all,

Is there a way to use the Package type to find the version number of an
installed RPM?

I've consulted this page [1] and I can't see any documentation there
that says this might be possible.

I want to simply query my package manager and ask which version of a
package is installed. I do not necessarily wish to ensure it is
upgraded, etc.

I know it's possible to do this with an exec call to rpm or yum, but I
want to do it "properly" :)

[1] http://docs.puppetlabs.com/guides/types/package.html


Cheers,
Jonathan


----------------------------
Jonathan Gazeley
Systems Support Specialist
ResNet | Wireless & VPN Team
IT Services
University of Bristol
----------------------------

Felix Frank

unread,
Jan 24, 2011, 8:31:10 AM1/24/11
to puppet...@googlegroups.com
On 01/24/2011 02:07 PM, Jonathan Gazeley wrote:
> Hi all,
>
> Is there a way to use the Package type to find the version number of an
> installed RPM?
>
> I've consulted this page [1] and I can't see any documentation there
> that says this might be possible.
>
> I want to simply query my package manager and ask which version of a
> package is installed. I do not necessarily wish to ensure it is
> upgraded, etc.
>
> I know it's possible to do this with an exec call to rpm or yum, but I
> want to do it "properly" :)
>
> [1] http://docs.puppetlabs.com/guides/types/package.html

Define "properly" :-) What is puppet supposed to do with this piece of
information? Log it somewhere?

Regards,
Felix

Jonathan Gazeley

unread,
Jan 24, 2011, 9:15:56 AM1/24/11
to puppet...@googlegroups.com

I want to place the version number in a variable, where it will be used
to do some post-install config that depends on the version number :)

By "properly" I meant to avoid exec calls unless as a last resort.

Cheers,
Jonathan

>
> Regards,
> Felix
>


--

Mohamed Lrhazi

unread,
Jan 24, 2011, 9:21:02 AM1/24/11
to puppet...@googlegroups.com
am just curious as to why do you think that would be possible? Did you
use some other "puppet type" to similarly obtain information? like get
the size of a file, using File type?

Thanks,
Mohamed.

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

Mohamed Lrhazi

unread,
Jan 24, 2011, 9:28:27 AM1/24/11
to puppet...@googlegroups.com
Just to clarify, I do not know the answer to your question... it's
just that I would not have had that question at all, so am wondering
why :)

Jonathan Gazeley

unread,
Jan 24, 2011, 9:31:53 AM1/24/11
to puppet...@googlegroups.com
On this page [1] it says that using Package with yum as a backend is
"versionable", i.e. "The provider is capable of interrogating the
package database for installed version(s), and can select which out of a
set of available versions of a package to install if asked."

The data (the version number) is clearly there, I just need a way of
getting at it!

Cheers,
Jonathan


[1] http://docs.puppetlabs.com/guides/types/package.html

>> ResNet | Wireless& VPN Team

R.I.Pienaar

unread,
Jan 24, 2011, 9:44:49 AM1/24/11
to puppet...@googlegroups.com

----- Original Message -----
> On this page [1] it says that using Package with yum as a backend is
> "versionable", i.e. "The provider is capable of interrogating the
> package database for installed version(s), and can select which out of
> a
> set of available versions of a package to install if asked."
>
> The data (the version number) is clearly there, I just need a way of
> getting at it!

The puppet model is not that the machine tells you what packages are on it
but that you tell the machine what state it should be in.

So lets say you're installing Foo then using puppet manifests you tell
the machine to install version 1.2.3. This is data in your manifests and
you should be able to use that data in other areas of your manifests if
lets say you stored it in extlookup or an external node classifier or even
node level variable.

The yum provider is versionable which means you can tell it to install version
1.2.3 of something and it will verify and ensure that version is there.

You need to think how you build machines from a different direction, you need
to think how you tell the machine its desired state rather than the machine
tell you what it is and then you make decisions based on that.


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.

--
R.I.Pienaar

Martijn Grendelman

unread,
Jan 24, 2011, 10:02:31 AM1/24/11
to puppet...@googlegroups.com
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.

donavan

unread,
Jan 24, 2011, 12:39:34 PM1/24/11
to Puppet Users
On Jan 24, 5:07 am, Jonathan Gazeley <jonathan.gaze...@bristol.ac.uk>
wrote:
> Hi all,
>
> Is there a way to use the Package type to find the version number of an
> installed RPM?

Have you seen 'ralsh', or 'puppet resource'[1]? You can use these
interactively to interrogate the state of a system, 'puppet resource
package foo'.
I don't recall if the common Package providers ouput more than 'ensure
=> absent|present". It's up to your provider (rpm, fbsd, etc) to
provide the state information in it's instances method. I imagine many
will only test presence, for speed. It should perfectly reasonable to
fork and create your own copy of the provider that queries for
versions etc.

[1] http://docs.puppetlabs.com/guides/tools.html#puppet-resource-or-ralsh
Reply all
Reply to author
Forward
0 new messages