A blog

Using MCollective with Chef

MCollective is a Ruby framework “to build server orchestration or parallel job execution systems”. Using messaging middleware (currently STOMP) for communication, a server running on each node can announce its existence, receive requests, and respond with structured data. Writing clients and agents is a straightforward exercise – while you’ll need to know enough Ruby to implement your desired functionality, the framework itself adds little complexity. A number of non-core plugins are available on github.

Although it often seems that MCollective goes hand-in-hand with Puppet, there’s no technical limitation behind this. It can quite readily be used with any other configuration management tool, or none at all. The plugins supporting integration with Puppet may be a little more mature today, but users of Chef won’t be missing out on anything.


To satisfy MCollective’s requirement for a STOMP server, it’s easiest to use ActiveMQ. For Ubuntu users, this can be easily installed using a cookbook from the Opscode site. After installation, we need to configure the service for use by MCollective – for simplicity, we’ll use the sample configuration from the Getting Started documentation.

See this gist for the necessary changes to the ActiveMQ cookbook.

The community site didn’t have a cookbook to install MCollective, so I’ve been working on one to fill the gap. I’ve released it on the community site, but be warned – this is my first attempt at writing a public cookbook, and your mileage may vary. You can find the source repository on github.


We can use Vagrant to make a simple demonstration using a single node. In practice, there’s not much point to running MCollective on just a single node – fortunately, using these cookbooks on a group of nodes (with Chef Server) is similarly straightforward. The repository for this demonstration is on github – the Vagrantfile specifies a “natty64” base box, but anything from “lucid” onwards should work.

Our first test that everything has worked is to use “mco ping”. This is an MCollective client command which broadcasts an echo request, and presents the replies from any mcollective servers which happen to be listening. As we’re running on a single node, we expect a single response:

Chef Integration

The cookbook incorporates the Chef integration code found in the MCollective documentation (link), with one small improvement – the code in the “Class filters” section has been implemented as a Chef handler, to avoid needing to pin a recipe at the end of the run list. The resulting inventory output looks something like this:


While relatively minor, there are several issues with the integration that I’m planning to work on. First, Ohai is a not especially fast. Although MCollective will cache its output, this means that requests might occasionally take several seconds to return (vs the typical tens-of-milliseconds latency). This is merely an annoyance during interactive use, but I expect it to be a problem for more sophisticated applications. An alternative approach used in the Puppet integration is to dump the facts into a YAML file, which MCollective then loads. Second, out of the box, Ohai appears to expose considerably more facts than Facter. I’m not convinced this is especially useful to MCollective, and I’m considering ways to filter the list down to facts I want to select or efficiently report on. Returning the data from only a specified list of Ohai plugins is my short-term plan. That said, I may yet change my mind about it being a problem – undesirably verbose “mco inventory” output is my only real complaint. Third, the list of Chef recipes reported to MCollective needs to be normalised. Depending upon how they made it into the expanded run list, a default recipe may be reported as either “recipe.cookbook” or “recipe.cookbook::default”. I’m not sure whether Chef should be taking care of this, or whether I should just fix it in the report handler.

Further Reading

Nicolas Szalay’s blog has some must-read entries demonstrating how to trigger Chef runs using MCollective, and how to create and use Chef resources from within MCollective agents. The MCollective Reference Guide on the Puppet Labs site is comprehensive and well-written. It’s worth spending some time browsing it to get a feel for what’s possible. In the next post, we’ll take a step back from MCollective and take a closer look at the cookbook itself.