Last active
November 5, 2018 19:23
-
-
Save dishbreak/ce868531c4e85bb3901c8affdb5a59d7 to your computer and use it in GitHub Desktop.
For each role on a chef server, display the number of servers with that role.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if ! which knife; then | |
( >&2 echo "Couldn't find knife on your path!" ) | |
exit 1 | |
fi | |
# Redirecting stderr to /dev/null will make output clean. | |
ROLES=$(knife role list 2>/dev/null) | |
# Bash delimits on whitespace, so you can use this to iterate over every role on the chef server. | |
for ROLE in $ROLES; do | |
# the -e flag returns the number of matches. | |
SERVER_COUNT=$(knife search "role:$ROLE" 2>/dev/null | grep -e "Node Name" ) | |
echo "$SERVER_COUNT $ROLE" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment