unifi ctx
About 924 words
List, switch and edit contexts.
Aliases: context, contexts
List, switch and edit contexts.
A context names a combination of an account (how to authenticate), a controller (what to talk to) and a default site. unifi login creates them; every command acts on the current context unless --context names another one.
Commands
unifi ctx current: Print the name of the current contextunifi ctx delete: Delete a contextunifi ctx describe: Show everything about a context and check that it worksunifi ctx get: List the contexts, or show oneunifi ctx rename: Rename a contextunifi ctx set: Change the site, account, controller or name of a contextunifi ctx use: Switch the current context
unifi ctx current
Print the name of the current context.
Usage
unifi ctx current [flags]Print the name of the current context, and nothing else, so that scripts can use it. Fails when no context is selected.
Examples
unifi ctx current
unifi ctx current --output jsonunifi ctx delete
Delete a context.
Usage
unifi ctx delete <context> [flags]Aliases: rm, remove
Delete a context from the configuration.
The account and the controller go with it when no other context uses them, and so does the account's API key in the credential store. The key itself stays valid: revoke it where you created it if it should stop working. unifi logout does the same for the current context.
Examples
unifi ctx delete lab
unifi ctx delete lab --yesFlags
| Flag | Description |
|---|---|
-y, --yes | do not ask for confirmation |
unifi ctx describe
Show everything about a context and check that it works.
Usage
unifi ctx describe [context] [flags]Show what a context resolves to: its account and where the API key is stored, its controller and how it is reached, and its default site.
Unless --offline is given, the controller is asked for its version and its sites, which proves that the address, the certificate and the API key all work. This is the first thing to run when a command cannot connect.
The command doubles as a health check: it exits 1 when the controller cannot be reached or rejects the API key, after showing what it found and what to do about it. With --offline nothing is checked and it exits 0.
Examples
unifi ctx describe
unifi ctx describe home --offline
unifi ctx describe home --output yaml
unifi ctx describe home > /dev/null || echo "home is down"Flags
| Flag | Description |
|---|---|
--offline | do not contact the controller |
unifi ctx get
List the contexts, or show one.
Usage
unifi ctx get [context] [flags]Aliases: list, ls
List the contexts of the configuration with the account, controller and default site each one resolves to. The current context is marked.
Examples
unifi ctx get
unifi ctx get home
unifi ctx get --output jsonunifi ctx rename
Rename a context.
Usage
unifi ctx rename <old> <new> [flags]Aliases: mv
Rename a context. It stays the current context when it was.
unifi login names the account and the controller of a context after it. When they still carry the old name and no other context uses them, they can be renamed along: on a terminal you are asked, in scripts pass --entries. The API key moves with the account in the credential store.
Examples
unifi ctx rename dream-machine-pro-max home
unifi ctx rename 192.168.1.1 home --entriesFlags
| Flag | Description |
|---|---|
--entries | also rename the account and the controller named after the context, when only it uses them |
-y, --yes | do not ask for confirmation; accepted by every command that changes something |
unifi ctx set
Change the site, account, controller or name of a context.
Usage
unifi ctx set [context] [flags]Change fields of a context; without an argument, of the current one.
A new default site is checked against the controller, and stored under the name the controller reports, unless --offline is given. An account or a controller must already exist in the configuration: unifi login creates them.
Examples
unifi ctx set --site "Lake House"
unifi ctx set home --name house
unifi ctx set lab --controller udm --account local --offlineFlags
| Flag | Description |
|---|---|
--account <string> | account to authenticate with |
--controller <string> | controller to talk to |
--name <string> | new name of the context |
--offline | do not check the site against the controller |
-s, --site <string> | new default site; empty selects the controller's default |
-y, --yes | do not ask for confirmation; accepted by every command that changes something |
unifi ctx use
Switch the current context.
Usage
unifi ctx use [context] [flags]Aliases: switch
Make a context the current one: every command acts on it unless --context names another. Without an argument, on a terminal, pick the context from a list.
Examples
unifi ctx use home
unifi ctx useFlags
| Flag | Description |
|---|---|
-y, --yes | do not ask for confirmation; accepted by every command that changes something |
Global flags
These flags are accepted by every command.
| Flag | Description |
|---|---|
--color-scheme <string> | color scheme: auto, dark or light |
--context <string> | context to use instead of the current one |
--no-cache | ask the controller for everything instead of using cached answers |
-o, --output <string> | output format: text, wide, json, yaml (table is another name for text) |
-s, --site <string> | site to act on instead of the context's default site |
--theme <string> | theme to render with instead of the configured one |
