[chef] Re: Conditional execution for custom resources


Chronological Thread 
  • From: Jesse Nelson < >
  • To: " " < >
  • Subject: [chef] Re: Conditional execution for custom resources
  • Date: Tue, 19 Mar 2013 04:22:07 -0700

Definitions aren't proper resources this should work as an LWRP tho. 




On Mar 19, 2013, at 1:54 AM, 
< >
 wrote:

> 
> 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.

§