Quickly Get 'alive' Member IPs in a Service Group


#1

I often find myself wishing for a quick list of alive member IPs for a given service group. Here’s a shell function to do that, and another I use for parallel ssh into hosts running members of the service group:

service_group_ips() {
  local initial_peer="$1"
  local service_group="$2"
  curl --silent "$initial_peer":9631/census \
    | jq -r ".census_groups | .\"$service_group\" | .population | .[] | select(.alive == true) | .sys | .ip"
}

habssh() {
  local initial_peer="$1"
  local service_group="$2"
  local pssh_command="$3"
  service_group_ips "$initial_peer" "$service_group" > "$HOME/.$service_group.ips"
  pssh --inline --hosts="$HOME/.$service_group.ips" "$pssh_command"
}