knife: obtaining two (or more) attributes in one go

I started looking at how to write my own knife plugin, but that was overkill. knife exec solved this problem rather elegantly and simply:

knife exec -E 'nodes.find(:name => "i-7a421114") { |n| puts "#{n.cloud.public_hostname} - #{n.cloud.local_hostname}" }'

And it's easy to extend this to as many attributes as required - simply keep adding n.[ATTRIB] to the closure.


As of today (Chef: 12.19.36) your second query actually works (and you can add as many attribs as you wish):

knife search node "chef_environment:production AND name:i-7a421114" -a cloud.public_hostname -a cloud.local_hostname