How to check if a package exists

4,542 views
Skip to first unread message

Sans

unread,
Apr 30, 2011, 5:12:04 AM4/30/11
to Puppet Users
Dear all,

I'm trying to do this. Say for example, I want this link: "liblcgdm.so
-> liblcgdm.so.1.8.0" to be present on the client only if "lcgdm-
libs-1.8.0-1sec.sl5" is already listed. I already have this to create
the link:

file {
'liblcgdm.so':
ensure => symlink,
name => '/opt/lcg/lib/liblcgdm.so',
target => 'liblcgdm.so.1.8.0';
}

but how do I check the existence of that particular package
beforehand? Thanks in advance for your time. Cheers!!

Rakhesh Sasidharan

unread,
Apr 30, 2011, 7:06:23 AM4/30/11
to puppet...@googlegroups.com
Hi Sans!

On Sat, 30 Apr 2011 02:12 -0700, "Sans" <r.sant...@gmail.com> wrote:
> Dear all,
>
> I'm trying to do this. Say for example, I want this link: "liblcgdm.so
> -> liblcgdm.so.1.8.0" to be present on the client only if "lcgdm-
> libs-1.8.0-1sec.sl5" is already listed. I already have this to create
> the link:
>
> file {
> 'liblcgdm.so':
> ensure => symlink,
> name => '/opt/lcg/lib/liblcgdm.so',
> target => 'liblcgdm.so.1.8.0';
> }
>


Not sure if this is the best way to do this, but one approach I would
try would be to use the Exec resource.

As in, have a Exec resource with a command to link the files above, but
which runs only if the file does not already exist. Something along the
lines of the example mentioned here -
http://www.puppetcookbook.com/posts/exec-onlyif.html

Regards,
Rakhesh

Matthew Black

unread,
Apr 30, 2011, 11:59:45 PM4/30/11
to puppet...@googlegroups.com
You can put a requires in the file resource

require => Package["packagename"]


then it will install the package first then put in the symlink.


--
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.


vagn scott

unread,
May 1, 2011, 12:48:16 AM5/1/11
to puppet...@googlegroups.com

Please look at

ldconfig -N

it will update the links for you.

You could try something like (warning untested)

class foo {
package { "liblcgdm":
notify => Exec[ "ldconfig::update" ],
}

include ldconfig::update
}

class ldconfig::update {
exec { "ldconfig -N":
refreshonly => true,
}
}

Of course, the package manager should set up these
links for you when installing the lib.

The other thing to note: If you are installing a library
without using the package manager you should run

ldconfig

anyway, in order to update your loader's idea of
what libraries exist, and where they are.
It also creates any missing links.

again, see ldconfig(8)

--
vagn

Steven Acres

unread,
May 1, 2011, 1:03:10 AM5/1/11
to puppet...@googlegroups.com

--
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.


As vagn noted, the package manager should be handling this, there most likely is a valid reason it isn't creating those links (aside from 'bugs'). And if you're sure you want to customize a pkg., re-roll the pkg. You'll thank yourself later, guaranteed.

--
Cheers,

Steven
-----------------------
Steven Acres
UNIX/Linux System Administrator

Sans

unread,
May 1, 2011, 2:21:08 AM5/1/11
to Puppet Users
On May 1, 4:59 am, Matthew Black <mjbl...@gmail.com> wrote:
> You can put a requires in the file resource
>
> require => Package["packagename"]
>
> then it will install the package first then put in the symlink.
>
That not what I actually want. I just simply want: if the package
already installed, create the sym-link otherwise, do nothing. Cheers!!

Rakhesh Sasidharan

unread,
May 1, 2011, 3:14:01 AM5/1/11
to puppet...@googlegroups.com

In that case my suggestion of yesterday should do the trick -

Have a Exec resource with a command to link the files above, but which


runs only if the file does not already exist. Something along the lines
of the example mentioned here -
http://www.puppetcookbook.com/posts/exec-onlyif.html

Regards.

Sans

unread,
May 1, 2011, 4:15:21 AM5/1/11
to Puppet Users
Hi Steven and vagn,

I almost forgot about ldconfig, I had a look now and ldconfig doesn't
appear to be working in this particular case. It's conventional for
the so_name to be the name+major version of the library (although, not
universally done), so ldconfig will create a link like "foo.so.1 ->
foo.so.1.1.1" and "foo.so.1.1 -> foo.so.1.1.1" but *not* foo.so ->
foo.so.1.1.1, as far as I understand. It should be created manually, I
suppose. Cheers!!


On May 1, 6:03 am, Steven Acres <ad...@swatteksystems.com> wrote:
> [ .... ]

Sans

unread,
May 1, 2011, 4:16:34 AM5/1/11
to Puppet Users
Thanks Rakhesh, looking into it. Cheers!!

Markus Falb

unread,
May 1, 2011, 8:21:25 AM5/1/11
to puppet...@googlegroups.com
On 1.5.2011 10:15, Sans wrote:
> Hi Steven and vagn,
>
> I almost forgot about ldconfig, I had a look now and ldconfig doesn't
> appear to be working in this particular case. It's conventional for
> the so_name to be the name+major version of the library (although, not
> universally done), so ldconfig will create a link like "foo.so.1 ->
> foo.so.1.1.1" and "foo.so.1.1 -> foo.so.1.1.1" but *not* foo.so ->
> foo.so.1.1.1, as far as I understand. It should be created manually, I
> suppose. Cheers!!

foo.so is normally provided by the foo-devel package.
Why do you need foo.so ?

--
Kind Regards, Markus Falb

signature.asc

jcbollinger

unread,
May 2, 2011, 10:27:14 AM5/2/11
to Puppet Users


On May 1, 2:14 am, "Rakhesh Sasidharan" <pup...@rakhesh.net> wrote:
An Exec can do this job, but the more Puppetly way to do it is to
write a custom fact (it's easy) that informs the Puppetmaster whether
lcgdm-
libs-1.8.0-1sec.sl5 is present. Wrap the delaration of your File
resource in a simple conditional (e.g. "if") statement based on that
fact. In general, when you want Puppet to vary its behavior based on
details of a particular node, facts and providers are the Puppet ways
to approach the problem.


John
Reply all
Reply to author
Forward
0 new messages