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
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.
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