edelight / chef-solo-search

Data bag search for Chef Solo
Apache License 2.0
177 stars 2 forks source link

Add cookbook vagrant-save #37

Closed greenmoss closed 10 years ago

greenmoss commented 11 years ago

Please add recipe vagrant-save, which automatically generates a JSON representation of each node that runs this recipe. The generated file can then be used in subsequent chef-solo-search searches.

rajivr commented 11 years ago

@greenmoss have you looked at chef-solo-extension? This saves node state after a chef run has completed. You get almost exactly the same data for search, as if you were using a chef server. I use this cookbook along with chef-solo-search.

greenmoss commented 11 years ago

@rajivr Thanks, I checked it out. The README doesn't really explain how it works: I gather from the library that it automatically writes the node data somewhere, though in a quick scan of the code I couldn't determine the location.

rajivr commented 11 years ago

@greenmoss Check out the file node_ext.rb in chef-solo-extention. The original Node#save method ignores node data when chef is running in solo mode. What this cookbook does is to proxy that behavior, and if chef is running in solo mode, it saves the node data locally, at the end of the chef run. (Saving node data at the end of the chef run is important so that node state can be captured correctly for search and other purposes!)

I've created this gist which might clarify things further. Here in chef-solo-extension/recipes/default.rb we're using chef to create a node directory, in case one does not exist. chef-solo-search uses this directory for its search. I've my run_list setup in such a way that I run chef-solo-extension before running chef-solo-search.

In chef-solo-extension/libraries/node_ext.rb on line 39 we specify the path where chef should save the node state. If chef was using the server, it calls the original method, otherwise it saves locally.

Hope this helps!

michaelglass commented 11 years ago

seems like this is kind of an unrelated feature.

greenmoss commented 11 years ago

@michaelglass Possibly, depending on how you look at it. The way I see it, generating json that is reusable by chef-solo-search could be considered the "other end of the loop" that is currently missing.

michaelglass commented 11 years ago

@greenmoss sorry, I don't have a lot of experience with hosted chef, which is what I think you're referring..

regardless: chef-solo-search handles search for chef-solo. something like chef-solo-persistence could be another library for your separate concern?

and a collection cookbook, e.g. chef-solo-for-hosted-recipes could be a recipe to provide hosted parity. Rather than jamming all the concerns into one place.

michaelglass commented 10 years ago

Closing this PR. Would love to include a reference to how users can use this functionality in the readme but it's definitely feature creep for this repo.