Skip to content

Instantly share code, notes, and snippets.

@threetee
Created January 20, 2012 13:24
Show Gist options
  • Save threetee/1647365 to your computer and use it in GitHub Desktop.
Save threetee/1647365 to your computer and use it in GitHub Desktop.
Opscode Chef - List/count EC2 instance AZ placement for your nodes with knife
#!/bin/sh
# Prints the number of nodes you have in each EC2 AZ
knife exec -E 'nodes.transform("*:*") {|n| puts "#{n.ec2.placement_availability_zone}"}' | awk '
{
for (i=1;i<=NF;i++)
count[$i]++
}
END {
for (i in count)
print count[i], i
}' $* | sort -r
#!/bin/sh
# Lists your nodes and their EC2 AZ placement
knife exec -E 'nodes.transform("*:*") {|n| puts "#{n.name}: #{n.ec2.placement_availability_zone}"}' | sort
# Note that you can get the same data with the knife search command below, but using knife exec lets you control the output format
# $ knife search node '*:*' -a ec2.placement_availability_zone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment