Skip to content

Instantly share code, notes, and snippets.

@jrwren
Created February 9, 2017 22:27
Show Gist options
  • Save jrwren/d19672314703010d60dec10f604cf185 to your computer and use it in GitHub Desktop.
Save jrwren/d19672314703010d60dec10f604cf185 to your computer and use it in GitHub Desktop.
Figuring out juju relations data using juju run

Juju relations can be confusing or deceptively simple, at first. Some background is here: https://jujucharms.com/docs/stable/authors-hook-environment

juju run runs commands in a Juju context, that is to say JUJU_CONTEXT_ID environment variable is set.

$ juju run --unit haproxy/0 'echo $JUJU_CONTEXT_ID'
haproxy/0-juju-run-9100131373820979914
$ juju run --unit haproxy/0 'echo $JUJU_CONTEXT_ID'
haproxy/0-juju-run-8230555870602207522

This means you can run charm hook tools.

For example, use relation-ids to see all of the reverse proxy relations for a given haproxy unit:

$ juju run --unit haproxy/0 'relation-ids reverseproxy'reverseproxy:110
reverseproxy:111
reverseproxy:112
reverseproxy:113
reverseproxy:114
reverseproxy:115
reverseproxy:116
reverseproxy:117
reverseproxy:118
reverseproxy:119

Wow! That is a lot of relations. Use relation-list to see the units for a given relation-id.

$ juju run --unit haproxy/0 'relation-list -r reverseproxy:115'
kibana/2

Ok, only one unit, kibana/2 for the kibana application. If there were more than one unit, both would be listed.

Now to see the relation data for each unit (in this case there is only one), use relation-get:

$ juju run --unit haproxy/0 'relation-get -r reverseproxy:115 - kibana/2'
host: 10.142.0.7
port: "80"
private-address: 10.142.0.7

There, now we know what data kibana charm is sending to haproxy charm.

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