[chef] Conditional resource creation / script execution


Chronological Thread 
  • From: Sébastien Pierre < >
  • To:
  • Subject: [chef] Conditional resource creation / script execution
  • Date: Wed, 13 Jan 2010 15:56:15 -0500
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=rUsGDCcpeYk3uWssxq4k3TrXKW2AFzOukIqGuDteWloTOmXvfJ/fucrs2Uh1v6nyG6 Ktvb3vAme0uiTc7iAPUu+GScCo3+RDlwqyjUtlsrYKZLRNZOfbbf/5u8bcVk3lpmZxRS dPbO98qZ25qaZQXbfSRAPegWo5I6tjEm0+mRs=

Hello,

I would like to know how to write "conditional" parts for recipies.

For instance, I would like to check if there is a "~/.ssh/id_dsa.pub" file and create it if necessary. Right now, the solution is rather inelegant

script "ssh-keygen" do
interpreter "bash"
user        "manage"
cwd         (HOME)
code        "mkdir ssh-temp"
code        "ssh-keygen -t dsa -f ssh-temp/id_dsa << EOF\n\nEOF"
code <<-EOH
if [ ! -f .ssh/id_dsa.pub ]; then
mv ssh-temp/* .ssh/
fi
rm -rf ssh-temp
EOH
end

while I would prefer

unless (File exists (HOME + "/.ssh/id_dsa.pub") script do
interpreter "bash"
user        "manage"
cwd         (HOME)
code        "ssh-keygen -t dsa -f ssh-temp/id_dsa << EOF\n\nEOF"
end

Is there a way to do this properly ?

 -- Sébastien



Archive powered by MHonArc 2.6.16.

§