Information Technology Reference
In-Depth Information
Example 6-3. node/info.rb
log "IP Address: #{ node [ 'ipaddress' ] } "
log "MAC Address: #{ node [ 'macaddress' ] } "
log "OS Platform: #{ node [ 'platform' ] } #{ node [ 'platform_version' ] } "
log "Running on a #{ node [ 'virtualization' ][ 'system' ] } \
#{ node [ 'virtualization' ][ 'role' ] } "
log "Hostname: #{ node [ 'hostname' ] } "
The syntax using #{<variable>} to print out information contained in variables should be
familiar to you. This is similar to what we did in Chapter 4 to access #{ENV['HOME']} . In
this case, the variable is node instead of ENV .
The log statements in Example 6-3 will produce the following output during your Chef run.
The use of log statements to show the content of attributes is a recommended Chef recipe
debugging technique:
INFO: IP Address: 10.0.2.15
INFO: MAC Address: 08:00:27:1C:AD:B6
INFO: OS Platform: centos 6.5
INFO: Running on a vbox guest
INFO: Hostname: default-centos65
You should still be logged into the node. Perform a Chef run using chef-client in local
mode. This time we will use the short options for --local-mode and --log_level . The out-
put should resemble the following:
[vagrant@default-centos65 learningchef]$ chef-client --local-mode info.rb \
--log_level info
...
Starting Chef Client, version 11.14.6
...
Converging 5 resources
Recipe: @recipe_files::/learningchef/info.rb
* log[IP Address: 10.0.2.15] action write[2014-08-14T12:36:05-07:00] INFO:
Processing log[IP Address: 10.0.2.15] action write (@recipe_files::/learning
chef/info.rb line 1)
[2014-08-14T12:36:05-07:00] INFO: IP Address: 10.0.2.15
* log[MAC Address: 08:00:27:1C:AD:B6] action write[2014-08-14T12:36:05-07:00]
INFO: Processing log[MAC Address: 08:00:27:1C:AD:B6] action write
Search WWH ::




Custom Search