Book Image

Mastering Chef

By : Mayank Joshi
Book Image

Mastering Chef

By: Mayank Joshi

Overview of this book

Table of Contents (20 chapters)
Mastering Chef
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Knife and Its Associated Plugins
10
Data Bags and Templates
Index

Running the Ohai binary


Ohai can be executed in stand-alone mode using the following command:

$ ohai
{
    …
  "kernel": {
    "name": "Linux",
    "release": "2.6.32-220.23.1.el6.x86_64",
    "version": "#1 SMP Mon Jun 18 18:58:52 BST 2012",
    "machine": "x86_64"
    …
}

The command scanned through the system, tried to fetch the required details such as kernel, platform, hostname, and so on, and eventually it emitted the output as JSON.

If you know which attributes to look out for, you can quickly write a wrapper around Ohai and use it to fetch the required details. For example, the following script will help you get the required attribute from Ohai output:

#!/usr/bin/env ruby
require 'json'
if ARGV.length != 1
  puts "Usage: cohai attribute . For e.g. - cohai kernel.release"
  exit 1
end
ohai_output = JSON.parse('ohai')')
ARGV[0].split(".").each do |key|
  ohai_output = ohai_output[key]
end
puts ohai_output

The Ohai binary searches for the available plugins in a predefined search path. If...