Information Technology Reference
In-Depth Information
In the following example, we pass a code block to (0..5).each . When you pass a code
block to an iterator method, it will execute the specified method for each item. In this case,
each item of the range (0..5) will be passed to our code block as the |counter| variable.
The block uses this variable to print out each value in the range:
( 0 . . 5 ) . each ddo | counter |
puts counter
end
end
We're doing something similar in Example 12-2 , iterating through each node item returned
by search() and returning the item content in the matching_node variable. matching_node
is a hash containing the key-value pairs in the node item.
The code just reads these values from the matching_node hash and uses the to_s method to
print a string representation of the object using log , which is the node name.
Run kitchen converge . If all goes well, you should notice that Test Kitchen uploads the
cookbook code to the sandbox environment and creates node entries in a chef-zero in-
stance. Then it runs the cookbook code, which performs a query for all nodes, printing out
the following results:
$ kitchen converge
-----> Starting Kitchen (v1.2.2.dev)
-----> Converging <default-centos65>...
Preparing files for transfer
Resolving cookbook dependencies with Berkshelf 3.1.3...
Removing non-cookbook files before transfer
Preparing nodes
...
Converging 4 resources
Recipe: nodes::default
* log[node[atwood]] action write
[2014-07-27T13:05:24-07:00] INFO: Processing log[node[atwood]] action
write (nodes::default line 12)
[2014-07-27T13:05:24-07:00] INFO: node[atwood]
* log[node[default-centos65]] action write[2014-07-27T13:05:24-07:00]
INFO: Processing log[node[default-centos65]] action write
(nodes::default line 12)
[2014-07-27T13:05:24-07:00] INFO: node[default-centos65]
Search WWH ::




Custom Search