Node Search for Chef Solo

Hi,

today we are releasing the third piece of Chef technology developed at
edelight, after the Chef Solo data bag search library and the MongoDB
cookbook two weeks ago.

LittleChef 1.0 adds a couple of tricks that make cookbooks nearly 100%
compatible for Chef Server and Chef Solo usage. Specifically, node
searches work, and you can set chef_environment in a role or node. The
following example will now be possible:
munin_servers = search(:node, “role:#{node[‘munin’][‘server_role’]}
AND chef_environment:#{node.chef_environment}”)

How? First a recap of how LittleChef works:

  • No Chef Server used
  • Your Chef repository should not only have roles and cookbooks, but
    also data bags and nodes (as JSON files)
  • The local checkout is called a “kitchen”
  • From a kitchen, you can call the “fix” command to trigger a Chef
    Solo configuration run for a node over SSH (fix node:mynodename). Node
    names should be their FQDN
  • LittleChef will then rsync the whole kitchen with that node’s
    chef-solo repo dir and then execute chef-solo

The new tricks for this release are:

Node Search

In the node “convergence” phase, LittleChef version 1.0 will
automatically add Markus’ chef-solo-search library to the node’s
cookbooks.

It will also build a data bag called “node”, and put there data bag
items for every node found in the local nodes/ directory. Now, the
attributes found in each node item won’t just be the explicit node
attributes, but the merged attributes. i.e., using the Chef precedence
rules, cookbook, role and node attributes will be merged, and some
automatic attributes will be added. As a result, when a node search is
performed in a recipe, Chef Solo will look for a data bag called
"node", and do the search there. Such a data bag will have been put
there automatically by LittleChef, and because the node items will
really have merged attributes, expanded role and recipe list, and most
things real node objects from a Chef Server would have, we have a
pretty good simulation of node search!

Needless to say, this approach can be emulated by other Chef Solo
users (Vagrant for example).

Environments

The last missing piece for all official cookbooks to be 100% usable
with Chef Solo were Environments. More precisely the
"chef_environment" value, which can normally not be set as an
attribute.

LittleChef will add a cookbook library which will make Chef Solo set
the chef_environment to the value found in solo.rb, which will have
been configured by LittleChef to be the merged attribute value.
The other Environment features like cookbook version pinning and
per-environment run-lists will still be missing, of course. This only
affects the value of chef_environment, which incidentally is all we
needed to make the node search queries work :wink:

Conclusion

Cookbooks should now be nearly 100% compatible for Chef Server and
LittleChef’s Chef Solo usage.

There are still a few exceptions, mostly MySQL related cookbooks that
use node.save, which is impossible to emulate. Examples:
https://github.com/opscode/cookbooks/blob/master/mysql/recipes/server.rb#L86
https://github.com/opscode/cookbooks/blob/master/wordpress/recipes/default.rb#L89

But we just avoid cookbooks relying on node.save, I guess we consider
it an anti-pattern.

So we are now enjoying being able to type
"fix node:node1,node2,node3"
and getting for example a MongoDB replicaset fully deployed,
orchestrated in the precise order we want :smiley:

Full announcement and changelog:
http://groups.google.com/group/littlechef/browse_thread/thread/82a1838e5f479d15#

Have a nice day!
Miquel