# Need to pass argument from recipe to another in cookbook

**URL:** <https://discourse.chef.io/t/need-to-pass-argument-from-recipe-to-another-in-cookbook/5745>\
**Category:** Chef Infra (archive)\
**Created:** [September 22, 2014, 9:56am UTC](https://discourse.chef.io/t/need-to-pass-argument-from-recipe-to-another-in-cookbook/5745 "2014-09-22T09:56:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ganesan\_A](https://avatars.discourse-cdn.com/v4/letter/g/f07891/32.png) [@Ganesan\_A](https://discourse.chef.io/u/Ganesan_A)\
**Post date:** [September 22, 2014, 9:56am UTC](https://discourse.chef.io/t/need-to-pass-argument-from-recipe-to-another-in-cookbook/5745/1 "2014-09-22T09:56:05Z")

</div>

Hi,

I had a cookbook with multiple recipes, in one of them having resources like

Path /root/chef-repo/cookbooks/rollback/recipes/default.rb

ruby\_block “Create a directry for backup” do  
block do  
FileUtils.mkdir node[‘backup\_path’] unless Dir.exists? node[‘backup\_path’]  
$s=FileUtils.mkdir node[‘new\_directory’]  
puts "directory#{$s}"  
end  
end

I need to pass this global variable $s to another chef resources in another  
recipe like Path /root/chef-repo/cookbooks/rollback/recipes/xxxx.rb, if is is  
possible how can i get that value during at run time or in any other way?

Thanks in advance,  
Ganesan.A

---

<div class="post-metadata">

**Author:** ![martinb3](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/martinb3/32/34_2.png) [@martinb3](https://discourse.chef.io/u/martinb3)\
**Post date:** [September 22, 2014, 12:29pm UTC](https://discourse.chef.io/t/need-to-pass-argument-from-recipe-to-another-in-cookbook/5745/2 "2014-09-22T12:29:02Z")

</div>

Hi there –

Sounds like a good use case for node.run\_state:

[https://docs.getchef.com/essentials\_cookbook\_recipes.html#node-run-state](https://docs.getchef.com/essentials_cookbook_recipes.html#node-run-state)

- Martin

* * *

From: [ganesan15785@gmail.com](mailto:ganesan15785@gmail.com) [ganesan15785@gmail.com]  
Sent: Monday, September 22, 2014 4:56 AM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Need to pass argument from recipe to another in cookbook

Hi,

I had a cookbook with multiple recipes, in one of them having resources like

Path /root/chef-repo/cookbooks/rollback/recipes/default.rb

ruby\_block “Create a directry for backup” do  
block do  
FileUtils.mkdir node[‘backup\_path’] unless Dir.exists? node[‘backup\_path’]  
$s=FileUtils.mkdir node[‘new\_directory’]  
puts "directory#{$s}"  
end  
end

I need to pass this global variable $s to another chef resources in another  
recipe like Path /root/chef-repo/cookbooks/rollback/recipes/xxxx.rb, if is is  
possible how can i get that value during at run time or in any other way?

Thanks in advance,  
Ganesan.A

---

<div class="post-metadata">

**Author:** ![Lamont\_Granquist\_OLD](https://avatars.discourse-cdn.com/v4/letter/l/7feea3/32.png) [@Lamont\_Granquist\_OLD](https://discourse.chef.io/u/Lamont_Granquist_OLD)\
**Post date:** [September 22, 2014, 5:02pm UTC](https://discourse.chef.io/t/need-to-pass-argument-from-recipe-to-another-in-cookbook/5745/3 "2014-09-22T17:02:23Z")

</div>

You probably just need a directory resource that notifies another  
resource when it creates the directory.

On 9/22/14, 2:56 AM, [ganesan15785@gmail.com](mailto:ganesan15785@gmail.com) wrote:

> Hi,
> 
> I had a cookbook with multiple recipes, in one of them having resources like
> 
> Path /root/chef-repo/cookbooks/rollback/recipes/default.rb
> 
> ruby\_block "Create a directry for backup" do  
> block do  
> FileUtils.mkdir node['backup\_path'] unless Dir.exists? node['backup\_path']  
> $s=FileUtils.mkdir node['new\_directory']  
> puts "directory#{$s}"  
> end  
> end
> 
> I need to pass this global variable $s to another chef resources in another  
> recipe like Path /root/chef-repo/cookbooks/rollback/recipes/xxxx.rb, if is is  
> possible how can i get that value during at run time or in any other way?
> 
> Thanks in advance,  
> Ganesan.A

---

<div class="post-metadata">

**Author:** ![jdunn](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jdunn/32/1800_2.png) [@jdunn](https://discourse.chef.io/u/jdunn)\
**Post date:** [September 23, 2014, 3:49am UTC](https://discourse.chef.io/t/need-to-pass-argument-from-recipe-to-another-in-cookbook/5745/4 "2014-09-23T03:49:47Z")

</div>

On Mon, Sep 22, 2014 at 5:56 AM, [ganesan15785@gmail.com](mailto:ganesan15785@gmail.com) wrote:

> I had a cookbook with multiple recipes, in one of them having resources like
> 
> Path /root/chef-repo/cookbooks/rollback/recipes/default.rb
> 
> ruby\_block "Create a directry for backup" do  
> block do  
> FileUtils.mkdir node['backup\_path'] unless Dir.exists? node['backup\_path']  
> $s=FileUtils.mkdir node['new\_directory']  
> puts "directory#{$s}"  
> end  
> end
> 
> I need to pass this global variable $s to another chef resources in another  
> recipe like Path /root/chef-repo/cookbooks/rollback/recipes/xxxx.rb, if is is  
> possible how can i get that value during at run time or in any other way?

I don't understand the complexity in this recipe code. Why a  
ruby\_block instead of built-in Chef resources? How come you don't just  
do

directory node['backup\_path'] do  
action :create  
end

And if you already have node['new\_directory'] as a node attribute, why  
can't you just consume it from the other recipe?

- Julian

--  
[Julian C. Dunn [jdunn@aquezada.com](mailto:jdunn@aquezada.com) \* Sorry, I'm ]  
[WWW: [http://www.aquezada.com/staff/julian](http://www.aquezada.com/staff/julian) \* only Web 1.0 ]  
[gopher://sdf.org/1/users/keymaker/ \* compliant!]  
[PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9]
