Knife: getting two (or more) attributes at a time

Currently, I can get one node attribute through knife search node as follows:

 knife search node "chef_environment:production AND name:i-7a421114" -a cloud.public_hostname # RESULT: i-7a421114: cloud.public_hostname: ec2-104-214-107-198.compute-1.amazonaws.com knife search node "chef_environment:production AND name:i-7a421114" -a cloud.local_hostname # RESULT: i-7a421114: cloud.local_hostname: ip-10-60-146-201.ec2.internal 

I want to get two attributes at the same time with a single call, something like this:

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

Of course, this does not work, only one attribute is obtained. Since I have almost no knowledge of the cook / knife, someone can let me know how to do this, or in some other way to achieve this.

+6
source share
2 answers

I started learning how to write my own knife plugin, but that was redundant. knife exec solve this problem is quite elegant and simple:

 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 you need - just keep adding n. [ATTRIB] to close.

+4
source

Today (chef: 12.19.36) your second request really works (and you can add as many attributes as you wish):

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

Source: https://habr.com/ru/post/946201/


All Articles