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

Hi there –

Sounds like a good use case for node.run_state:

https://docs.getchef.com/essentials_cookbook_recipes.html#node-run-state

  • Martin

From: ganesan15785@gmail.com [ganesan15785@gmail.com]
Sent: Monday, September 22, 2014 4:56 AM
To: 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

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

On Mon, Sep 22, 2014 at 5:56 AM, 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 * Sorry, I’m ]
[ WWW: 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 ]