Information Technology Reference
In-Depth Information
Debugging Attributes
If you need to debug where attributes are being set, the node object exposes a helpful
node.debug_value()
method. Let's say, for example, you did not know that
ohai
set
node['ipaddress']
using automatic precedence. You could determine this by using
node.debug_value()
.
Modify
recipes/default.rb
as shown in
Example 8-10
. Because we have access to the full
power of the Ruby language in a Chef recipe, we also make use of the “pretty printer for
Ruby objects” function included with the core Ruby library. This function will print out the
contents of a Ruby object in a more readable format. The
node.debug_value()
returns the
raw contents of an object;
pp
just makes the output look nicer.
Example 8-10. chefdk/motd-attributes/recipes/default.rb
#
# Cookbook Name:: motd-attributes
# Recipe:: default
#
# Copyright (C) 2014
#
#
#
require
'pp'
node
.
default
[
'ipaddress'
] =
'1.1.1.1'
pp node
.
debug_value
(
'ipaddress'
)
node
.
default
[
'motd-attributes'
][
'company'
] =
'My Company'
node
.
default
[
'motd-attributes'
][
'message'
] =
"It's a wonderful day today!"
include_recipe
'motd-attributes::message'
template
'/etc/motd'
ddo
source
'motd.erb'
mode
'0644'
end
end
When you run
kitchen converge
, you should see the following output:
$
kitchen converge
-----> Starting Kitchen (v1.2.2.dev)
...