Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Last active May 12, 2021 19:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nottrobin/4e2a94db24ac9daddcee6996ad4c1062 to your computer and use it in GitHub Desktop.
Save nottrobin/4e2a94db24ac9daddcee6996ad4c1062 to your computer and use it in GitHub Desktop.
To clean out a Juju model so you can use it from scratch, without deleting and recreating it
# Clear out a model, for Juju 2
# ==
# Destroy all machines and remove applications
# --
clean_model() {
model_name=${1}
juju status --model ${model_name} --format json | jq '.machines' | jq -r 'keys[]' | xargs -n 1 juju remove-machine --force # Force destroy all machines
juju status --model ${model_name} --format json | jq '.applications' | jq -r 'keys[]' | xargs -n 1 juju remove-application # Remove all applications
watch -c -n 10 juju status --model ${model_name} --color
}
# Other useful commands
# ==
juju status --format json | jq '.machines' | jq -r 'keys[]' # Get all machines
juju status --format json | jq '.applications' | jq -r 'keys[]' # Get all applications
juju status --format short | awk '{print $2}' | sed -E 's/:$//' # Get all units
juju status --format short | awk '{print $2}' | sed -E 's/:$//' | xargs -n 1 juju resolved --no-retry # Resolve all problems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment