Target Ops Manager BOSH Director using om and jq

When debugging Ops Manager problems you sometimes want to directly interact with the BOSH director. This procedure is well documented, however I wanted a more automated way of doing it.

So without further ado I present my solution using the bosh v2 cli, om (Ops Manager cli) and jq:

# Required variables
export OM_TARGET=__TARGET__;
export OM_PASSWORD=__PASSWORD__;
# Unset BOSH_* env vars
while read var; do unset $var; done < <(env | grep BOSH | cut -d'=' -f1)
# Get director ip
BOSH_PRODUCT_GUID=$(om -t $OM_TARGET -k -u admin curl -s -path /api/v0/deployed/products/ | jq -r -c '.[] | select(.type | contains("p-bosh")) | .guid');
export BOSH_ENVIRONMENT=$(om -t $OM_TARGET -k -u admin curl -s -path /api/v0/deployed/products/$BOSH_PRODUCT_GUID/static_ips | jq -r '.[].ips[]');
# Director root cert
export BOSH_CA_CERT=$(om -t $OM_TARGET -k -u admin curl -s -path /api/v0/certificate_authorities | jq -r '.certificate_authorities[].cert_pem');
# Director credentials
export BOSH_USERNAME=$(om -t $OM_TARGET -k -u admin curl -s -path /api/v0/deployed/director/credentials/director_credentials | jq -r '.credential.value.identity');
export BOSH_PASSWORD=$(om -t $OM_TARGET -k -u admin curl -s -path /api/v0/deployed/director/credentials/director_credentials | jq -r '.credential.value.password');
# Log-in to get UAA token
echo -e "$BOSH_USERNAME\n$BOSH_PASSWORD\n" | bosh log-in;
bosh env;

Spread the word

twitter icon facebook icon linkedin icon