Information Technology Reference
In-Depth Information
ohai
output is in JavaScript Simple Object Notation (JSON) form. JSON is a commonly
used format for machine-readable output, as it can be easily parsed into the object-represent-
ation used for programming languages like Ruby. Although you can run
ohai
as a standalone
application, this is not very common. Instead, the output of
ohai
is intended to be read by
machines, specifically by
chef-client
and associated tools, so JSON is the perfect format.
chef-client
reads the JSON output from
ohai
and converts it into a
node
object, which is
accessible by your Chef code.
You can refer to the node's IP address in your code with the following
attribute
. An attribute
is a variable maintained by Chef. In your code, you specify a quoted string in a pair of brack-
ets with the name used as an index in the collection, then Chef will return the value. In this
case, we want to know the IP address. By referring to the prior
ohai
output, Chef knows the
index name is
ipaddress
:
node
[
'ipaddress'
]
We used an attribute variable in our Chef code back in
Recipes Specify Desired Configura-
Name/value pair collections can be nested. This is what is indicated in the multiple levels of
indentation in the
ohai
output. So to access the kind of virtualization software we are using
(the “virtualization system”), use the following nested set of name/value pair references, be-
cause
system
is a name/value pair within the
virtualization
collection:
node
[
'virtualization'
][
'system'
]