Book Image

Chef Infrastructure Automation Cookbook

By : Matthias Marschall
Book Image

Chef Infrastructure Automation Cookbook

By: Matthias Marschall

Overview of this book

Table of Contents (14 chapters)
Chef Infrastructure Automation Cookbook Second Edition
About the Author
About the Reviewers

Running the same command on many machines at once

A simple problem with so many self-scripted solutions is logging in to multiple boxes in parallel, executing the same command on every box at once. No matter whether you want to check the status of a certain service or look at some critical system data on all boxes, being able to log in to many servers in parallel can save you a lot of time and hassle (imagine forgetting one of your seven web servers when disabling the basic authentication for your website).

How to do it...

Let's try to execute a few simple commands on multiple servers in parallel:

  1. Retrieve the status of the nginx processes from all your web servers (assuming you have at least one host up and running, which has the role web_server):

    mma@laptop:~/chef-repo $ knife ssh 'role:web_server' 'sudo sv status nginx' run: nginx: (pid 12356) 204667s; run: log: (pid 1135) 912026s run: nginx: (pid 19155) 199923s; run: log: (pid 1138) 834124s