/ chef

Stream command output from a Chef recipe

In this article I will show you how to see, in real-time, a command output from a Chef recipe.

Executing a command, the chef way

As a command example, as I'm working with it right now, let's take the Kubernetes installation tool: kubeadm.

This app tells you what he is doing in its output.

I first did this:

While this runs the command successfully, all the command's output is invisible:

* execute[kubeadm init] action run
           - execute     kubeadm init     --token=vfopfv.fgum14jkv3ldssu8     --pod-network-cidr=10.244.0.0/16     --service-cidr=10.96.0.0/12     --service-dns-domain=cluster.local     --apiserver-advertise-address=172.28.128.200

Executing a command, the Ruby way

Let's now make this real-time :

Now you get the command output in real time:

         * ruby_block[kubeadm init] action run[init] Using Kubernetes version: v1.15.1
       [preflight] Running pre-flight checks
       [preflight] Pulling images required for setting up a Kubernetes cluster
       [preflight] This might take a minute or two, depending on the speed of your internet connection
       ...

🎉

Stream command output from a Chef recipe
Share this