How to interchange data between different recipes on open source chef


#1

Hi,

I have two recipes my open source chef server and need to interchange some
data between them. I wondering how to do that. If someone give a hint, it
will much appreciated.

PS: I tried to write the data into a databag, but failed as below. It looks
like recipes save data into a databag is allowed.

*Net::HTTPServerException

405 “Method Not Allowed”

Cookbook Trace:

/var/chef/cache/cookbooks/mysql/recipes/server.rb:34:in `from_file’

Relevant File Content:

/var/chef/cache/cookbooks/mysql/recipes/server.rb:

30:
31: #if Chef::DataBag.list.key?(‘unique_name’)
32: new_databag = Chef::DataBag.new
33: new_databag.name(‘unique_name’)
34>> new_databag.save
35: #end
36: *

Thanks,
Sam


#2

I have not done it myself, but I did think editing databags from a recipe
was possible, and is documented here:
http://docs.opscode.com/essentials_data_bags.html#create-and-edit

If you don’t need the data to persist across chef runs (IE you just need to
exchange it during the course of a single run) I have used the node. run_state variable.
so something like:
recipe1.rb:
node.run_state[:my_data] = "Hello"
recipe2.rb:
puts node.run_state[:my_data]

I have two recipes my open source chef server and need to interchange some

data between them. I wondering how to do that. If someone give a hint, it
will much appreciated.

PS: I tried to write the data into a databag, but failed as below. It
looks like recipes save data into a databag is allowed.

*Net::HTTPServerException

405 “Method Not Allowed”


#3

++

I use this method in the reboot-handler cookbook (https://github.com/retr0h/cookbook-reboot-handler/blob/master/files/default/reboot.rb)

John

On Monday, September 9, 2013 at 8:37 PM, David Petzel wrote:

I have not done it myself, but I did think editing databags from a recipe was possible, and is documented here: http://docs.opscode.com/essentials_data_bags.html#create-and-edit

If you don’t need the data to persist across chef runs (IE you just need to exchange it during the course of a single run) I have used the node.run_state variable.
so something like:
recipe1.rb:
node.run_state[:my_data] = "Hello"
recipe2.rb:
puts node.run_state[:my_data]

I have two recipes my open source chef server and need to interchange some data between them. I wondering how to do that. If someone give a hint, it will much appreciated.

PS: I tried to write the data into a databag, but failed as below. It looks like recipes save data into a databag is allowed.

Net::HTTPServerException

405 “Method Not Allowed”


#4

On Monday, September 9, 2013 at 8:12 PM, Sam Su wrote:

Hi,

I have two recipes my open source chef server and need to interchange some data between them. I wondering how to do that. If someone give a hint, it will much appreciated.

PS: I tried to write the data into a databag, but failed as below. It looks like recipes save data into a databag is allowed.

Net::HTTPServerException

405 “Method Not Allowed”

Cookbook Trace:

/var/chef/cache/cookbooks/mysql/recipes/server.rb:34:in `from_file’

Relevant File Content:

/var/chef/cache/cookbooks/mysql/recipes/server.rb:

30:
31: #if Chef::DataBag.list.key?(‘unique_name’)
32: new_databag = Chef::DataBag.new
33: new_databag.name (http://new_databag.name)(‘unique_name’)
34>> new_databag.save
35: #end
36:

Data bags can be a little awkward. A data bag is just a container into which you can put data bag items. Since the data bag part doesn’t have any data, there’s nothing to update, which is what you’re trying to do here. For what you’re trying to do, data bag items would work.

That said, for passing in-memory data between recipes within a chef run, you’re better off setting node attributes or using the node.run_state hash.

Thanks,
Sam

HTH,


Daniel DeLeo


#5

Hi Sam,

sam.debian@gmail.com writes:

I have two recipes my open source chef server and need to interchange some
data between them. I wondering how to do that. If someone give a hint, it
will much appreciated.

PS: I tried to write the data into a databag, but failed as below. It looks
like recipes save data into a databag is allowed.

*Net::HTTPServerException

405 “Method Not Allowed”

I think the error you are seeing is this bug:

https://tickets.opscode.com/browse/CHEF-4435

You might try creating the data bag ahead of time since actual data
lives in a data bag item in a given data bag.

  • seth


Seth Falcon | Development Lead | Opscode | @sfalcon