How to access the current values ​​from the cook data package?

I have a server controlled by a chef. I need to access some values ​​that live in a cookbook data bag from scripts that are not executed by the chef.

/ * Chef REST API allows you to access the values ​​of data bags, as seen on the Chef server. This is not what I want. In each chef-client run, a series of coordinated changes may appear, including changes to the data packet. If the data on the server has already been changed, but the chef-client has not yet been performed locally, the local configuration and the data packet on the server side may not be synchronized. * /

I see two solutions:

  • Parsing / importing a data file in /var/cache/chef/cookbooks/<book-name> , since it is more or less regular Ruby.
  • Inside the recipe, upload the appropriate data from the data packet to a simple file accessible from my scripts.

Are there any better options?

+7
source share
1 answer

Dropping data from hash file bags or node data into a separate file is a good way to exchange information between the Chef server and scripts running on the node. If your script can parse JSON, then this is really easy:

 file "/etc/script.json" do owner "root" group "root" mode 0644 content node[:whatever].to_json end 

Using the chef's REST interface sounds like overkill, and groping in / var / cache / chef is just rude. (-:

+7
source

All Articles