Chef-provisioning and test kitchen

Is it possible to use the chef-provisioning resources from test kitchen, from inside a regular recipe?

We’ve created a cookbook which currently lets us create various nodes defined in suites in .kitchen.yml. For one of the nodes, we need to run a registration command on another, previously instantiated node. We do it by using the kitchen-nodes provisioner, searching for the target node from whithin the recipe, and use ssh to access it and run the command.

However, I think it’d be much more elegant to have chef itself run the command on the target node, and prevent cross-ssh altogether. So, I’m looking into chef-provisioning and the machine and machine_execute resources it provides. But I’m kind of stuck at this point - if I simply depend on the gem in metadata.rb, and use those resources in my recipe, I get “cannot load such file -- chef/provisioning” (the gem is installed on my workstation). And also, I barely can find any examples clarifying how to use this whole thing.

I’m relatively new to chef, so maybe I’m on completely wrong track with my approach.

Possible, yes. Recommend, almost certainly not.

Kitchen doesn’t inherently support multiple nodes at this time though it’s the defining feature of the 2.0 roadmap and we have an RFC here. That said, anything you try to do along those lines will be brittle and bespoke. On top of that, chef-provisioning has it’s own complicated history and most definitely isn’t going to be easy to run inside of kitchen - at that point it’s turtles all the way down and you’ve created something unnecessarily complex/painful.

While it might be possible with enough familiarity to run provisioning from kitchen it’s very much not a supported use case and I’d discourage you as strenuously as possible not to pursue that path. Using recipes that require coordination with other nodes/recipes is also somewhat of an anti-pattern in the Chef world because of the nature of convergent systems frameworks so any approach here will be tricky at best, miserable at worst.


Well, I more or less understand. That said, what’s a better approach to develop/test a cookbook which defines several, interoperating nodes, installation of some of which requires running some commands on another node?

You might want to take a look at Kitchen Terraform. I haven’t used it
personally but I was working with a customer who said they’d been using it
for awhile and gave it high marks.

Matt Ray
Regional Manager, Solutions Architect - APJ :: Chef
AUS: +61 457 231 372
US: +1 512 731 2218
mattray :: GitHub :: IRC :: Slack :: Twitter