Skip to content

snippet

Snippet management commands for NDCLI. Snippets are reusable configuration blocks that define users, groups, aliases, and firewall rules. Snippets are combined into templates to create complete configurations.

Snippet content is JSON for every type. NDAgent talks to OPNsense through its REST API for all of them; each snippet’s content is the JSON payload the agent will hand to the matching OPNsense endpoint.

TypeDescription
USERUser definition (OPNsense auth/user)
GROUPGroup definition (OPNsense auth/group)
ALIASNetwork alias — host, network, or port set (OPNsense firewall/alias)
RULEFirewall rule (OPNsense firewall/filter)
UNBOUND_HOST_OVERRIDEUnbound DNS host override — A/AAAA/MX/TXT record
UNBOUND_DOMAIN_FORWARDUnbound DNS domain forwarding (incl. DoT)
UNBOUND_HOST_ALIASUnbound DNS host alias (CNAME-style, references a host override)
UNBOUND_ACLUnbound DNS query ACL
ZABBIX_SETTINGSZabbix Agent global settings — singleton; NDAgent owns the full local/main/tuning/features tree on every apply
ZABBIX_USERPARAMETERZabbix UserParameter (custom check command). Key must start with nd-
ZABBIX_ALIASZabbix item-key alias. Key must start with nd-
CommandDescription
snippet listList snippets
snippet describeShow snippet details
snippet createCreate a new snippet
snippet deleteDelete a snippet
snippet editEdit snippet in external editor
snippet pullPull snippet from a device
snippet renameRename a snippet
snippet set-prioritySet snippet priority
snippet update-contentUpdate snippet content from file

List snippets in your organization.

Terminal window
ndcli snippet list [flags]
FlagTypeDefaultDescription
--namestringFilter by name (regex pattern)
--typestringFilter by type: USER, GROUP, ALIAS, RULE, UNBOUND_HOST_OVERRIDE, UNBOUND_DOMAIN_FORWARD, UNBOUND_HOST_ALIAS, UNBOUND_ACL, ZABBIX_SETTINGS, ZABBIX_USERPARAMETER, ZABBIX_ALIAS
--created-afterstringFilter by created date
--created-beforestringFilter by created date
--updated-afterstringFilter by updated date
--updated-beforestringFilter by updated date
--sort-bystringpriority:ascSort field: priority, name, created_at, updated_at
--pageint1Page number
--per-pageint50Items per page (max 100)
Terminal window
ndcli snippet list
ndcli snippet list --type RULE
ndcli snippet list --type ALIAS
ndcli snippet list --name "admin.*"
ndcli snippet list --updated-after 24h
ndcli snippet list --sort-by name:asc

Show detailed information about a snippet including its content.

Terminal window
ndcli snippet describe [name]
ArgumentRequiredDescription
nameYesSnippet name

Shows:

  • Snippet name and type
  • Priority
  • Full content
  • Creation and update timestamps
  • Templates using this snippet
Terminal window
ndcli snippet describe admin-users
ndcli snippet describe firewall-rules -f json

Create a new snippet.

Terminal window
ndcli snippet create [name] [flags]
ArgumentRequiredDescription
nameYesSnippet name
FlagTypeDefaultDescription
--typestringRequiredSnippet type: USER, GROUP, ALIAS, RULE, UNBOUND_HOST_OVERRIDE, UNBOUND_DOMAIN_FORWARD, UNBOUND_HOST_ALIAS, UNBOUND_ACL, ZABBIX_SETTINGS, ZABBIX_USERPARAMETER, ZABBIX_ALIAS
--contentstringSnippet content (inline)
--filestringRead content from file
--priorityint1000Priority (1-60000, lower = higher priority)
Terminal window
ndcli snippet create web-servers \
--type ALIAS \
--content "host web1 { 192.168.1.10 }
host web2 { 192.168.1.11 }"
ndcli snippet create firewall-rules \
--type RULE \
--file ./rules.conf
ndcli snippet create critical-rules \
--type RULE \
--file ./critical.conf \
--priority 100

Priority determines the order snippets are applied (lower numbers = higher priority):

RangeSuggested Use
1-500Critical/foundational rules
500-1000Core infrastructure
1000-2000Standard configurations
2000-5000Application-specific rules
5000+Optional/override rules

Delete a snippet.

Terminal window
ndcli snippet delete [name]
ArgumentRequiredDescription
nameYesSnippet name to delete
Terminal window
ndcli snippet delete deprecated-rules

Open a snippet’s content in your system’s default text editor for editing.

Terminal window
ndcli snippet edit [name]
ArgumentRequiredDescription
nameYesSnippet name
  1. Downloads current snippet content to a temporary file
  2. Opens the file in your default editor ($EDITOR or system default)
  3. After you save and close, uploads the modified content
  4. If no changes were made, no update occurs
VariableDescription
EDITORPreferred text editor (e.g., vim, nano, code)
VISUALAlternative editor variable
Terminal window
ndcli snippet edit firewall-rules
EDITOR=nano ndcli snippet edit firewall-rules

Pull configuration content from a device and optionally save it as a snippet.

Terminal window
ndcli snippet pull [device] [snippet-name] [flags]
ArgumentRequiredDescription
deviceYesDevice name to pull from
snippet-nameYesName for the pulled content
FlagTypeDefaultDescription
--typestringALIASConfig type to pull (see match semantics below): USER, GROUP, ALIAS, RULE, UNBOUND_HOST_OVERRIDE, UNBOUND_DOMAIN_FORWARD, UNBOUND_HOST_ALIAS, UNBOUND_ACL, ZABBIX_SETTINGS, ZABBIX_USERPARAMETER, ZABBIX_ALIAS
--auto-createboolfalseCreate snippet in DB if it doesn’t exist
--overwriteboolfalseUpdate snippet if it already exists
--wait-wfalseWait for task to complete
Terminal window
ndcli snippet pull fw-prod-01 production-aliases --type ALIAS
ndcli snippet pull fw-prod-01 production-aliases --type ALIAS --wait
ndcli snippet pull fw-prod-01 new-rules \
--type RULE \
--auto-create \
--wait
ndcli snippet pull fw-prod-01 existing-aliases \
--type ALIAS \
--overwrite \
--wait

The snippet-name argument doubles as the lookup key on the device. How it’s interpreted depends on --type:

TypeLookup
USERexact username
GROUPexact group name
ALIASexact alias name
RULEpartial description match (case-insensitive); fails if multiple match
UNBOUND_HOST_OVERRIDEhostname.domain (e.g. server1.local)
UNBOUND_DOMAIN_FORWARDdomain name (e.g. internal.corp)
UNBOUND_HOST_ALIAShostname.domain (e.g. www.local)
UNBOUND_ACLACL name (e.g. lan-clients)
ZABBIX_SETTINGSsingleton — name is the destination snippet name only; the agent returns the full Zabbix Agent settings tree
ZABBIX_USERPARAMETERexact UserParameter key (e.g. nd-cpu-temp)
ZABBIX_ALIASexact item-alias key (e.g. nd-uname)

By default, snippet pull creates an asynchronous task and returns immediately with a task ID. Use --wait to block until completion, or check task status with:

Terminal window
ndcli task describe <task-id>

Rename a snippet.

Terminal window
ndcli snippet rename [name] [new-name]
ArgumentRequiredDescription
nameYesCurrent snippet name
new-nameYesNew snippet name
Terminal window
ndcli snippet rename old-rules new-rules

Change a snippet’s priority.

Terminal window
ndcli snippet set-priority [name] [priority]
ArgumentRequiredDescription
nameYesSnippet name
priorityYesNew priority (1-60000)
Terminal window
ndcli snippet set-priority critical-rules 100
ndcli snippet set-priority optional-rules 5000

Update a snippet’s content from a file.

Terminal window
ndcli snippet update-content [name] [file]
ArgumentRequiredDescription
nameYesSnippet name
fileYesPath to file containing new content
Terminal window
ndcli snippet update-content firewall-rules ./updated-rules.conf
cat new-content.conf | ndcli snippet update-content my-snippet /dev/stdin