#!/usr/bin/env bash set -euo pipefail # try_usernames_awx.sh # Patch an existing AWX Machine credential (id 5) with candidate usernames # and run an ad-hoc ping against the three static hosts until one succeeds. AWX_HOST="${AWX_HOST:-http://192.168.49.2:30081}" AWX_USER="${AWX_USER:-admin}" AWX_PASS="${AWX_PASS:-Aase#1234!}" CRED_ID="${CRED_ID:-5}" INV_ID="${INV_ID:-2}" USERS=(admin alex alexpolo ubuntu core ec2-user root ansible) for u in "${USERS[@]}"; do echo echo "===> Trying username=$u" TMPPATCH=$(mktemp) # build JSON with a literal "$encrypted$" for ssh_key_data so AWX keeps the stored key printf '{"inputs":{"username":"%s","ssh_key_data":"$encrypted$"}}' "$u" > "$TMPPATCH" curl -sS -u "$AWX_USER:$AWX_PASS" -H "Content-Type: application/json" -X PATCH "$AWX_HOST/api/v2/credentials/$CRED_ID/" -d "$TMPPATCH" -o /tmp/patch_resp.json || true jq -r '.name, .inputs.username' /tmp/patch_resp.json || cat /tmp/patch_resp.json TMPADHOC=$(mktemp) cat > "$TMPADHOC" <