# How can I call include\_recipe only on true condition?

**URL:** <https://discourse.chef.io/t/how-can-i-call-include-recipe-only-on-true-condition/10993>\
**Category:** Chef Infra (archive)\
**Created:** [June 9, 2017, 2:01pm UTC](https://discourse.chef.io/t/how-can-i-call-include-recipe-only-on-true-condition/10993 "2017-06-09T14:01:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChefLearner](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@ChefLearner](https://discourse.chef.io/u/ChefLearner)\
**Post date:** [June 9, 2017, 2:01pm UTC](https://discourse.chef.io/t/how-can-i-call-include-recipe-only-on-true-condition/10993/1 "2017-06-09T14:01:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![budgester](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/budgester/32/1004_2.png) [@budgester](https://discourse.chef.io/u/budgester)\
**Post date:** [June 9, 2017, 3:19pm UTC](https://discourse.chef.io/t/how-can-i-call-include-recipe-only-on-true-condition/10993/2 "2017-06-09T15:19:59Z")

</div>

are you using the execute resource ?

have a look at using guards in your recipes.

[https://docs.chef.io/resource\_common.html#guards](https://docs.chef.io/resource_common.html#guards)

And example/snippet of you chef recipe is always useful

---

<div class="post-metadata">

**Author:** ![ChefLearner](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@ChefLearner](https://discourse.chef.io/u/ChefLearner)\
**Post date:** [June 12, 2017, 4:56am UTC](https://discourse.chef.io/t/how-can-i-call-include-recipe-only-on-true-condition/10993/3 "2017-06-12T04:56:23Z")

</div>

Hi,  
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]
then
  
	<<< check if host IP is not present, then do registration>>

else

```

no action as IP is already present  
fi

```
# Logout from server
./vmssc logout server	

```

EOH  
end

# Invoke addGPtoHost recipe if guard point exists

if node[‘guardPointsList’].strip != ""  
include\_recipe 'gde\_client::addGPtoHost’  
end
