[chef] RE: How to check whether a package is installed ?


Chronological Thread 
  • From: Kevin Keane Subscription < >
  • To: < >
  • Subject: [chef] RE: How to check whether a package is installed ?
  • Date: Thu, 10 Oct 2013 02:07:28 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=sendgrid.info; h=subject:from:to:mime-version:content-type:in-reply-to:references:sender; q=dns; s=smtpapi; b=ppxOmFhf5jL0sQACIoCVZnwiBbORZ5Za7PtuxRTSeSzL 9z9yndgR2gtNJDlhr1wMSUeqy61eiv+OpuhMmIawWRT/S59+okjBXVWZL964I+BU 6bx+xnaTthZL2u7IV7I7egqVi/jHfFBEpALjGTqIn3w2MWwfgHWuUKbetLZJUfs=

Title: RE: [chef] How to check whether a package is installed ?

What exactly are you trying to accomplish? There are two different scenarios I can think of, and you can address them in two different ways.

Scenario 1: you want to install MySQL, and then perform another action. In that case, you would simply use the package resource, which would then notify your execute resource. In that case, your actions will only execute once right after the package gets installed.

Scenario 2: you want to execute your action only on those servers that already have MySQL installed. In this case, the generic solution would be to use an automatic attribute that Chef automatically populates at the beginning of the chef run (actually, Ohai does the populating). In that case, your actions will be executed on every single Chef run.

The first scenario is probably closer to what Chef is intended for. The second scenario means that your action isn't idempotent as Chef expects.

Kevin Keane

The NetTech

760-721-8339

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html


-----Original message-----
From: Hui Hu < >
Sent: Thursday 10th October 2013 0:17
To:
Subject: [chef] How to check whether a package is installed ?

Hi Chef,

Is there a simple chef way to check whether a package is installed or a service is running ?

For example, I want to write some code like this :

do-work if package('mypkg').installed?
do-work if service('mysvr').running?

I know we can do it by the code below, but it's bind to the specific platform. What I need is a platform independent way.

execute "..." do
  only_if "rpm -q mypkg"
  only_if "service mysvr status"
end

Thanks
Jesse Hu,  Project Serengeti



Archive powered by MHonArc 2.6.16.

§