Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Last active April 27, 2018 03:53
Show Gist options
  • Save nottrobin/9e7ff961cc6c00a65c61 to your computer and use it in GitHub Desktop.
Save nottrobin/9e7ff961cc6c00a65c61 to your computer and use it in GitHub Desktop.
Get the machine number for the first unit of a juju service
#!/usr/bin/env bash
# Get the machine number for the first unit of a juju service
# Requires:
# - `jq` (http://stedolan.github.io/jq/)
# Usage:
# $ juju-machine-number.sh my-awesome-service
# 12
service_name=${1}
juju status --format json | jq -r '.services|.["'${service_name}'"]|.["units"]|.["'${service_name}'/0"]|.["machine"]'
@notjames
Copy link

notjames commented Apr 27, 2018

A more proper way:

juju status --arg service_name $service_name --format json | jq -r '.services|.["$service_name"]|.["units"]|.["$service_name"]|.["machine"]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment