On demand chef runs with Chef Waiter

Randy Coburn
Nov 2 · 2 min read
Photo by Avi Richards on Unsplash

In the beginning there was just a chef

Chef. You know, these guys: https://www.chef.io/.
They have a pretty sweet product. However it was lacking a bit for us, so I wrapped it with a service and called it “Chef Waiter”. I want to share it with you.

Get it here: https://github.com/morfien101/chef-waiter

Chef Waiter is a wrapper that gives the chef client a simple to use HTTP API. It replaces the chef-client service on your servers. It’s mainly focused around human interactions but is very easy to use with a CI/CD tool.

In a nutshell you can do the following:

  • Start chef runs on demand for both “normal” and “one time” runs
  • Read logs from runs
  • Check the status of a run on demand
  • Stop/Start/Set periodic run timers

Why would you wan to use something like this?

Consider that you have your chef client setup to run every 30 minutes. You release a change to the cookbooks. Do you really want to wait up to 30 minutes before the next run? Having no determined time for the runs.
No?
You can poke the API on the chef waiter and initiate a run on demand instead.

Maybe in a CI/CD environment, you create a new package of your app that chef deploys for you, you update the versions on the environment and then release it to all the servers on demand. You can watch the progress of the run on each server and finally collect the logs. Think something like:

# Some extremely butchered pseudo python code as an example: 
for each server in <chef environment>:
new process:
server-run-id = curl <server>:8901/chefclient
waiting = true
while waiting:
details = curl <server>:8901/chefclient/<server-run-id>
if details["status"] = complete:
waiting = false
print(curl <server>:8901/cheflogs/<server-run-id>)

But I could just use SSH/WinRM for this?

You could, but you expose extremely powerful protocols to your CI/CD/Users when you do that. Also you have to do (N*number of systems) scripts to do the same job. Also you don’t get all the features that Chef Waiter brings to the table. But yes, it’s a simple alternative if you just want a simple tool.

How do you get it?

Chef Waiter can be installed using a cookbook. This is used in bootstraps and upgrades.
https://supermarket.chef.io/cookbooks/chef-waiter

The code is in Github and you can download a release from there directly. Currently I only build for Windows and Linux but I could do more if the need arises.
https://github.com/morfien101/chef-waiter

There is a example repo where I use a container to build out a demo environment:
https://github.com/morfien101/medium-chef-waiter

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade