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


Chronological Thread 
  • From: "steve ." < >
  • To: " " < >
  • Subject: [chef] Re: Re: RE: How to check whether a package is installed ?
  • Date: Fri, 11 Oct 2013 12:55:41 -0700

Seems like you'd need an ohai plugin that queries the RPM database and pops that into a node attribute.  Then it's as simple as declaring the resources with "only_if { node[:packages].include?('mysql-server') } " , or whatever the package name is.

Surely someone's written an OSS Ohai plugin that does this already...



On Fri, Oct 11, 2013 at 3:27 AM, Hui Hu < " target="_blank"> > wrote:
Thanks Kevin.  Scenario 2 is what I want.  How to use Ohai automatic attribute to check whether a pacakge is installed or a service is running ? 

What I want is some code like this :


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

Thanks
Jesse Hu,  Project Serengeti


2013/10/10 Kevin Keane Subscription < " target="_blank"> >

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 < " target="_blank"> >
Sent: Thursday 10th October 2013 0:17
To: " target="_blank">
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.

§