#!/usr/bin/env bash # ------------------------------------------------------------------ # Grab the list of IPs # ------------------------------------------------------------------ readarray -t ips < <(curl -s http://192.168.37.1:5000/client_inventory | grep ansible_host | cut -d: -f2 | awk '{print $1}') # ------------------------------------------------------------------ # Inspect the result (optional, handy for debugging) # ------------------------------------------------------------------ echo "Found ${#ips[@]} IP(s):" for ip in "${ips[@]}"; do echo " $ip" done # ------------------------------------------------------------------ # Use the array – for example, SSH into each host # ------------------------------------------------------------------ USER="root" KEY="~/.ssh/id_rsa" PORT=22 for host in "${ips[@]}"; do echo "=== SSHing to $host ===" ssh -o BatchMode=yes -p "$PORT" -i "$KEY" "$USER@$host" "hostname && docker ps --format=json | jq -r '.Names' | grep cosmostat" echo done