Closed bpo closed 12 years ago
Very cool! Can you elaborate on how you model your chef nodes in flat files?
If I understood you correctly, LittleChef does something similar. Before every configuration run it creates a node data bag (with merged attributes), which allows recipes to use search(:node, ...)
without any modifications to the current chef-solo-search lib. Why do you needed this patch to do search over a node
data bag? and how do you create the flat files yourself?
The existing chef-solo-search lib yields objects of type DataBagItem - how that could work if a recipe expects Chef::Node objects? I'll have to have a look at how LittleChef works.
With regard to modeling chef nodes in flat files: I don't have a good process for that yet. Nodes are written by hand or rendered ERB templates.
Chef Solo doesn't expect Chef::Node objects. A search(:node, "role:monitoring")
statement in a recipe, when executed by Chef Solo, using this library, will return DataBagItems inside the data bag "node" that match the search criteria. If your nodes are saved as individual DataBagItems (one JSON file per node) inside data_bags/node/
, it just works.
Hi,
I understand that chef-solo-search presently could return DataBagItems in response to a search(:node, xxx)
- that's what my patch fixes. When running in a Chef Server environment, search(:node, xxx)
returns Chef::Node objects, which have a different interface from DataBagItems. This patch prevents some of the need to rewrite cookbooks for chef-solo. A couple of examples: node.recipe?("apt") or node.run_list.role_names - these will fail in the current edition of chef-solo-search.
I took a look at the way LittleChef works. It seems like it would be possible to get it working with my patch by writing out the appropriate json_class
in the json files it generates. I don't think I'll pursue LittleChef myself - it seems to duplicate many of the internal data structures of Chef in Python, which feels brittle to me. I'd like to share my method of generating node configs, but that might take a while.
Feel free to discard this pull request if it's not in the direction you want to take this project.
Thanks for the useful tool! --bpo
Thanks for taking the time to explain your thinking clearly. We didn't encounter compatibility problems probably because we don't use syntax like node.run_list.role_names
.
I definitely want to test your patch. Mainly whether our node search continues working with it. In principle any change that improves cookbook compatibility between Chef Solo and Server is great!
Regarding your method of generating node configs, you say you are going to share it but it may take a while. Could you then briefly explain what it consists in?
I checked it out and works well so far. Good job thanks!
@tobami Glad to hear it. Did you find it to work with littlechef with no changes?
As far as I can tell yes! If we find any problem with cookbooks we have not yet tested I will let you know
Hi,
This patch corrects an error in the existing tests and adds simple support for keeping a model of your chef nodes in flat files (sort of a special type of data bag).
This has been useful for me when modeling complex environments without chef-server. Comments welcome.
Cheers, --bpo