[chef] Conditional execution for custom resources


Chronological Thread 
  • From: < >
  • To:
  • Subject: [chef] Conditional execution for custom resources
  • Date: Tue, 19 Mar 2013 01:54:36 -0700 (PDT)


In custom resource, is the conditional execution using only_if/not_if
supported? I tried but didn't work for me. Is there any Chef defined mechanism
for conditional execution of custom resources?

Lets take scenario : Install RPM if it is already not installed.

So defined new custom resource in 'definitions' directory under cookbook 

define :remote_execute, :command => false, :condition => false do
            execute "remote_command" do
                command "#{params[:command]}"
#                not_if "#{params[:condition]}"     <<<< Ideally, I don't want
to pass condition parameter; but one can achieve similar functionality by 
doing
this.
            end
end

In my recipe I am calling remote_execute as below. 

remote_execute "rexe_rpm" do
    command "sudo rpm -ivh
/home/aditya/Downloads/libyaml-0.1.4-1.el6.rf.x86_64.rpm"
    not_if "rpm -qa | grep yaml"                 <<<< this is not honored in
case of custom resource. 
#    condition "rpm -qa | grep yaml"       <<<< If I pass condition parameter,
it works as expected. 
end



Thanks,
Aditya Nitsure



Archive powered by MHonArc 2.6.16.

§