netbox-cli
full-featured cli for the netbox api. covers standard crud resources and a raw mode for any endpoint.
install
from crates.io:
from this repo:
quickstart
--url, --token, --profile, --output, --select, --columns, --max-columns and --dry-run are global (netbox-cli [OPTIONS] <COMMAND>) and must come before the subcommand; every other flag (--query, --json, --file and the rest) belongs to the subcommand and comes after it.
auth
credentials can come from (in priority order):
- CLI flags:
--url,--token - Environment variables:
NETBOX_URL,NETBOX_TOKEN - Config file profiles
config profiles
create ~/.config/netbox-cli/config.toml:
[]
= "https://netbox.example.com"
= "NETBOX_TOKEN"
[]
= "https://netbox.prod.example.com"
= "pass show netbox/prod-token"
= 60
= true
= "table"
profile fields:
url- netbox instance urltoken- plain token (not recommended)token_env- env var containing tokentoken_command- command to get token (e.g., password manager)timeout- request timeout in secondsretries- max retry attemptsssl_verify- verify ssl certificates (default: true)output- default output format (json, yaml, table)
use a profile:
manage config:
resources
list resource groups:
common commands
list:
get by id:
create/update with json:
output formats
select a field with a dot path:
select path examples
the --select flag uses dot notation to navigate nested structures. when traversing arrays, the path applies to each element.
basic field selection:
# get just the results array from a paginated response
# get the count field
nested object navigation:
# get the site object from each device
# get the site name from each device
# get the device type's manufacturer name
array mapping:
when the path crosses an array, subsequent segments apply to each element:
# response: {"results": [{"name": "sw1"}, {"name": "sw2"}]}
# --select results.name produces: ["sw1", "sw2"]
# response: {"results": [{"tags": [{"name": "prod"}, {"name": "dc1"}]}, ...]}
# --select results.tags.name produces: [[\"prod\", \"dc1\"], ...]
combining with output formats:
# extract names and output as yaml
# extract nested field for table display
table output flattens paginated responses by showing the results rows and a summary line with count/next/previous when present.
table column control
specify which columns to show in table output:
change the maximum number of auto-selected columns (default: 6):
when --columns is specified, only those columns are shown. when not specified, columns are auto-selected from preferred fields (id, name, display, status, etc.) up to --max-columns.
over a list of plain values rather than objects (e.g. --select results.id), there are no fields to project: a single --columns name is used as the header, and two or more fall back to a single value column. the header does not depend on how many rows came back. a list that mixes plain values with objects or nested lists also falls back to value, because those rows are summarised rather than printed and no single name describes them all.
dry run
print the request for write operations without sending them:
raw requests
use raw for any endpoint:
notes:
--pathis api-relative, e.g.dcim/devices/- a leading
api/is stripped if present - repeat
--query key=valuefor multiple params
graphql
read-only graphql queries:
special endpoints
ipam availability
list and create from available pools:
background task management
control background tasks:
sync and render operations
sync config contexts, templates, and render configs:
circuit and cable paths
get path information for terminations:
dcim trace
trace cable paths through infrastructure:
vm config rendering
render configuration for virtual machines:
output
responses are json, pretty-printed to stdout. errors return non-zero exit codes.
exit codes:
0success1request or parsing error2invalid command or arguments
errors include http status, path, and request id when available.
help