Previous
Overview
Create a fragment (a reusable configuration template), add the components, services, and modules your machines need, then apply that fragment to every machine in your fleet. When you update the fragment, every machine that uses it picks up the change.
Use fragments when you have multiple machines that share the same configuration, either entirely or with small per-machine differences. Common examples:
If every machine has a unique configuration with nothing in common, direct per-machine configuration may be simpler.
The fragment editor works just like the machine configuration editor. You can use the visual Builder to add resources, or switch to the JSON view to edit the configuration directly.
In the fragment editor sidebar, click + to add:
Click Save after adding and configuring your resources.
The fragment’s resources now appear on the machine’s configuration page. The machine downloads and applies the configuration on its next sync.
To apply a fragment to many machines, use the CLI in a loop or script:
viam machines part fragments add --part=<part-id> --fragment=<fragment-id>
See automate with scripts for examples of scripting fleet operations.
If a machine already has a resource with the same name as one in the fragment, or if you apply the same fragment twice, you need a prefix to avoid name collisions.
When you insert a fragment that would cause a conflict, the UI prompts you for a prefix. The prefix is prepended to every resource name from the fragment. For example, a component named camera-1 in a fragment with prefix front becomes front-camera-1.
Fragments support variable substitution for values that differ between machines. Define a variable in the fragment’s JSON configuration using the $variable syntax, then set the value when applying the fragment to each machine.
In the fragment’s JSON editor, replace a value with a variable placeholder:
{
"components": [
{
"name": "$sensor_name",
"model": "viam:sensor:ultrasonic",
"type": "sensor",
"attributes": {
"trigger_pin": "$trigger_pin",
"echo_int_pin": "$echo_pin"
}
}
]
}
When you apply this fragment to a machine, set the variable values in the fragment card’s Variables section. Any variables you don’t set use the placeholder value as a default.
Sometimes you need to change a single value from a fragment without creating a new fragment. Use fragment overrides (called “fragment mods” in JSON) to modify, add, or remove specific fields.
In the machine’s CONFIGURE tab, find the fragment card and click the field you want to change. Modified fields are highlighted to show they differ from the fragment’s default.
In JSON mode, overrides use MongoDB update operator syntax in the fragment_mods array:
{
"fragment_mods": [
{
"fragment_id": "abcd1234-5678-efgh-ijkl-mnopqrstuvwx",
"mods": [
{
"$set": {
"components.motor1.attributes.max_rpm": 200
}
}
]
}
]
}
Supported operators: $set (change or add a value), $unset (remove a value).
Every time you save a fragment, Viam creates a new revision. You can pin machines to a specific revision or use tags to control rollouts.
On the machine’s CONFIGURE tab, find the fragment card and look for the Update version section:
stable and development.stable at your current production revision.stable tag.development at the new revision.development and verify the changes work.stable to the new revision. All production machines update.You can configure default fragments at the organization level so that every new machine in the organization automatically uses them. Default fragments are applied when a machine is created, whether manually or through provisioning.
To configure default fragments, use the fleet management API’s UpdateOrganization method with the default_fragments field.
In JSON mode on a machine’s CONFIGURE tab, fragments are listed in the fragments array. Each entry supports:
| Field | Type | Description |
|---|---|---|
id | string | The fragment ID. Required. |
version | string | Pin to a specific revision number or tag name. Omit to track the latest revision. |
prefix | string | A string prepended to all resource names from this fragment. Use to avoid name collisions. |
variables | object | A map of variable names to values, overriding the defaults defined in the fragment. |
Example:
{
"fragments": [
{
"id": "abcd1234-5678-efgh-ijkl-mnopqrstuvwx",
"version": "stable",
"prefix": "front",
"variables": {
"sensor_name": "front-ultrasonic",
"trigger_pin": "15",
"echo_pin": "16"
}
}
]
}
After applying a fragment to a machine:
To see the fully resolved configuration with all fragments expanded, click … (actions menu) on the machine page and select View debug configuration.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!