Variables
Variables allow you to parameterize snippet content so the same snippet can produce different configurations for different devices or OUs. Inside a snippet’s JSON content, you can use ${variable_name} placeholders that are resolved at sync time.
Variable Scopes
Variables are defined at multiple levels, and more specific scopes override broader ones:
| Priority | Scope | Meaning |
|---|---|---|
| 1 (lowest) | Organization | The default value for all devices in the organization. |
| 2 | OU | Overrides the organization value for all devices in a specific OU. |
| 3 | Template | Overrides the value for all snippets within a specific template. |
| 4 (highest) | Device | Overrides all other values for a specific device. |
For example, if you define ${listen_port} at the organization level as 51820, you could override it to 52830 for a specific OU’s devices, or to 53840 for one particular device — all while using the same snippet definition.
Parameterizing a Snippet
Consider a snippet that allows DNS queries. Instead of hardcoding the DNS server addresses, you can use a variable:
{ "uuid": "221f3268-0003-4abc-9000-000000000001", "enabled": true, "action": "pass", "interface": "lan", "direction": "in", "ipprotocol": "inet", "protocol": "TCP/UDP", "source_net": "any", "destination_net": "${dns_server}", "destination_port": "53", "description": "Allow DNS to ${dns_server}"}Then define the variable at different scopes:
ndcli variable org create dns_server 8.8.8.8This sets the default DNS server for all devices in the organization. Now override it for the production OU to use an internal resolver:
ndcli variable ou create production dns_server 10.0.1.53And for a specific branch device that needs a local DNS:
ndcli variable device create fw-branch-austin dns_server 10.50.1.53At sync time, the variable is substituted before the configuration reaches the device:
fw-hq-primary(production OU) resolves${dns_server}to10.0.1.53fw-branch-austin(branch-offices OU, device override) resolves to10.50.1.53fw-guest-lobby(guest-networks OU, no override) resolves to8.8.8.8(org default)
Conflict Detection
If a device belongs to multiple OUs that define the same variable with different values, NetDefense detects the conflict and prevents the sync.
Managing Variables
# List all variables across scopesndcli variable overview
# Create variables at each scopendcli variable org create <name> <value>ndcli variable ou create <ou-name> <name> <value>ndcli variable template create <template-name> <name> <value>ndcli variable device create <device-name> <name> <value>