Skip to content

Instantly share code, notes, and snippets.

@jghiloni
Created May 12, 2018 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jghiloni/bda15ec4f4df776a358df3cac74f2c9a to your computer and use it in GitHub Desktop.
Save jghiloni/bda15ec4f4df776a358df3cac74f2c9a to your computer and use it in GitHub Desktop.
Use the OM tool to apply changes with errands disabled for THAT RUN ONLY
#!/bin/bash
set -eu
opsman() {
om -t OPSMAN_URL -k -u OPSMAN_USER -p OPSMAN_PASSWORD -f json "$@"
}
OFS=$IFS
IFS=$'\n'
sub_json='{}'
for pdesc in $(opsman curl -s -p /api/v0/staged/products | jq -r '.[] | .type + "," + .guid'); do
name=$(echo $pdesc | cut -d, -f1)
guid=$(echo $pdesc | cut -d, -f2)
errand_json=$(opsman errands -p $name)
if [[ ! -z "${errand_json}" ]] && [[ "${errand_json}" != "null" ]]; then
echo "Temporarily disabling errands for $name ..."
sub_json=$(echo "${sub_json}" | jq --arg guid $guid '. + { ($guid): { "run_post_deploy": {} } }')
errands=$(echo "${errand_json}" | jq -r '.[] | select(.post_deploy_enabled=="true") | .name')
for errand in $errands; do
sub_json=$(echo "${sub_json}" | jq --arg guid $guid --arg errand $errand '.[$guid].run_post_deploy += {($errand): false}')
done
fi
done
body=$(jq -n --argjson errands "${sub_json}" '{ "deploy_products":"all", "ignore_warnings": true, "errands": $errands }')
echo "Applying changes..."
opsman curl -x POST -d "${body}" -s -p '/api/v0/installations'
IFS=$OFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment