Viewing Chef Node Attributes with Knife
Mark Mzyk | February 5, 2013
This is a simple post to list all the ways you can view Chef node attributes with knife, even nested attributes, which is harder than it feels like it should be.
A lot of this information can be found at docs.opscode.com, but as of this writing the examples for knife node show don’t always go into enough detail.
knife raw was a part of the knife-essentials gem but as of Chef 11 has been integrated into standard knife. If you aren’t running Chef 11, you can install the knife-essentials gem.
Show basic info about the node, truncated and nicely formated:
knife node show <node_name>
Show all the information about a node, nicely formated:
knife node show -l <node_name>
Three ways to list node information, in the raw json form (note the -l or –long option is needed to return all node data for knife node show so that all node attribute data is included)
knife node show -l -F json <node_name>
knife node show -l --format=json <node_name>
knife raw /nodes/<node_name>
How to list a single node attribute:
knife node show <node_name> -a <attribute_name>
attribute_name will be something like kernel or platform.
However, this doesn’t work for nested attributes, such as node[kernel][machine], as knife node show doesn’t understand nested attributes.
If you don’t want to use the raw json and grep, you can find a nested attribute by doing a search:
knife search node <query_to_run> -a <main_attribute>.<nested_attribute>
An example:
knife search node name:<node_name> -a kernel.machine
Hopefully this is useful information to others. Information on using search to find nested attributes was originally found on this log of the #chef irc channel.