How can I call include_recipe only on true condition?


i have a bash code wherein it executes if few linux commands and also have if… else loop
After completion of bash resource I am calling include_recipe.

But now I want include_recipe to get called only for if loop in bash resource and skip if it goes to else loop

How can I achieve that?


are you using the execute resource ?

have a look at using guards in your recipes.

And example/snippet of you chef recipe is always useful


No. I am not using execute resource. I am using bash resource in which I have if… else loop
after completing bash resource, I am running include_recipe

Now I want to run include_recipe <receipe 2> only if “if” part in bash resource is true and not for else loop

How can I do that?

snippet is herewith

bash ‘Host registration with server’ do
cwd node[‘local’][‘download_dir’]
sensitive true
user "root"
code <<-EOH
# Login to server
<<<< steps to login to to server and check IP address >>

if [ $? != 0 ]
	<<< check if host IP is not present, then do registration>>


no action as IP is already present

# Logout from server
./vmssc logout server	


Invoke addGPtoHost recipe if guard point exists

if node[‘guardPointsList’].strip != ""
include_recipe 'gde_client::addGPtoHost’