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
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 "..." doonly_if "rpm -q mypkg"
only_if "service mysvr status"endThanksJesse Hu, Project Serengeti
Archive powered by MHonArc 2.6.16.