Reuse machine configuration on many machines
Fragments allow you to share configurations for one or more resources across multiple machines.
For example, you may use the same networking credentials across rovers and robotic arms. Another example is a fleet of rovers that use a fragment to configure the motors, base component, and other components.
Create a fragment
You must be an organization owner to create fragments for an organization.
Go to the FRAGMENTS page and create a fragment in your organization.
Add and configure all the resources you want to use on your machines.
Fragments support all available resources except triggers. You can also add other fragments inside a fragment.
Tip: Switch to JSON
If you already created a machine to test your configuration, you can Switch to JSON, copy its JSON configuration and paste it into the fragment.

Add variable templates.
Fragments support variable substitution, allowing you to use the same fragment for multiple use cases even if there are small differences in configuration.
When configuring resources, click the JSON button to switch to the JSON editor.
Instead of a key value, add a variable in the form "$variable": { "name": "placeholder" } }}.
For example:
{
"api": "rdk:component:camera",
"attributes": {
"preloaded_image": {
"$variable": {
"name": "placeholder"
}
}
},
"model": "rdk:builtin:image_file",
"name": "camera-placeholder"
}
{
"api": "rdk:component:camera",
"attributes": {
"preloaded_image": "dog"
},
"model": "rdk:builtin:image_file",
"name": "camera-placeholder"
}
Set your privacy settings in the menu bar. There are three options for this:
- Public: Any user inside or outside of your organization will be able to view and use this fragment.
- Private: No user outside of your organization will be able to view or use this fragment.
- Unlisted: Any user inside or outside of your organization, with a direct link, will be able to view and use this fragment.
Click Save.
Add a description
While not required, we recommend you add a description to your fragment from the fragment’s page.
Tip: Organize resources into folders
If you have many components and services in one fragment, you can add folders to your fragment and use them to organize the resources.
Add the fragment to machines
With your fragment created, you can add it to any number of machines.
In the following steps, you will see how to add a fragment manually. If you are working in a factory setting and need to set up devices before they reach the end user, you can also use fragments to provision your machines.
On your machine’s CONFIGURE tab, click the + button and select Insert fragment.
Search for your fragment and add it.
Click Save in the upper right corner of the screen.
Add variables if the fragment uses variable templates.
In the fragment’s panel, find the Variables section and add them to the JSON object. For example:
{
"placeholder": "dog"
}
Click Save in the upper right corner of the screen.
Repeat step 1 for each of the machines that you want to configure in the same way.
If some of your machines have slight differences, you can still add the fragment and then add fragment overwrites in the next section.
Modify fragment settings on a machine
If some of your machines are similar but not identical, you can use a fragment with all of them and then overwrite parts of the configuration to customize it without modifying the upstream fragment.
For example, consider a fleet of rovers that all have the same motors, wheels, and base but a few rovers have a different camera than most. You can configure a fragment that has the motors, wheels, base on the rovers as well as the camera that is used on most rovers. For the rovers that have a different camera, you would then add the fragment and overwrite the camera configuration.
If you or a collaborator later modify fields within the upstream fragment, your modifications will still apply. For example if you changed the default camera configuration in the fragment to be a different camera model, your modified rovers would still overwrite the camera model set by the fragment.
On the CONFIGURE tab of the machine whose config you want to modify, make your edits just as you would edit a non-fragment resource.
You can click the JSON button to switch to the JSON editor and see the changes.
Click Save.
You can modify fragment fields in your machine’s raw JSON config by using update operators.
Viam supports all update operators except for $setOnInsert, $, $[], and $[<identifier>].
To configure fragment overwrites manually instead of using the builder UI:
- Navigate to your machine’s CONFIGURE tab.
- Switch to JSON mode.
- Add a top-level section called
"fragment_mods"(alongside the other top-level sections like"components"and"fragments"):
"fragment_mods": [
{
"fragment_id": "<YOUR FRAGMENT ID>",
"mods": [
{
<INSERT YOUR MODS HERE>
}
]
}
],
This example assumes the fragment with ID abcd7ef8-fa88-1234-b9a1-123z987e55aa contains a motor configured with "name": "motor1".
{
"components": [],
"fragment_mods": [
{
"fragment_id": "abcd7ef8-fa88-1234-b9a1-123z987e55aa",
"mods": [
{
"$set": {
"components.motor1.attributes.max_rpm": 1818,
"components.motor1.attributes.pins.a": 30,
"components.motor1.attributes.board": "local"
}
},
{
"$unset": {
"components.motor1.attributes.pins.pwm": 0
}
}
]
}
],
"fragments": [
{
"_id": "abcd7ef8-fa88-1234-b9a1-123z987e55aa"
}
]
}
- Edit the
fragment_idvalue to match the ID of the fragment you want to modify, for example"12345678-1a2b-9b8a-abcd987654321". - Add any update operators you’d like to apply to the fragment to the
modssection. Click to view each example:
- Click Save in the upper right corner of the page to save your new configuration.
- To check that your mods are working, view your machine’s debug configuration. In Builder mode on the CONFIGURE tab, select the … (Actions) menu to the right of your main part’s name in the left-hand panel and click the View debug configuration option to view the full configuration file.
After configuring fragment overwrites, check your machine’s LOGS tab.
If there are problems with overwrites to the fragment, the overwrites will not be partially applied and the configuration changes will not take effect until the configuration is fixed.

(Optional) Revert fragment modifications.
If you need to restore the original fragment, click the … in the upper right corner of the card you modified, and click Revert changes. Now, the fragment will be identical to the upstream fragment.
Update a fragment
You and your collaborators can edit a fragment at any time. Viam automatically creates new versions of your fragment as you make changes. Fragments can only be deleted if no machines are using them.
If you’ve already deployed the fragment to one or more machines, Viam updates the configuration on each deployed machine that uses that fragment. You can see the number of machines using your fragment from the fragments page.
Test updates first
We recommend testing updates to fragments on a small number of machines before deploying them to a larger fleet. For recommendations on updating software on deployed machines, see Update software.
Create fragment tags
You can create tags to differentiate between versions of your fragment.
For example, you may want to create a tag for stable and beta.
- Go to the FRAGMENTS tab and click on a fragment.
- Click on Versions in the menu bar.
- Click Add Tag.
- Select a version to pin the tag to. You can change this later.
- Type in a name for your tag.
Pin to a fragment version or tag
When you add a fragment to a machine you can choose to pin the fragment version to use:
- the latest version: Always update to the latest version of this fragment as soon as a new version becomes available. This is the default.
- a specific version: Do not update to any other version.
- a tag: Always use the version of this fragment with the selected tag.
For example
stableorbeta.
Add fragment prefix
Resource names must be unique on each machine.
To avoid name collisions with resources you add using a fragment, you can set a prefix.
If set, all resource added through the fragment have the prefix.
For example, a component with the name arm-1 configured in a fragment with the configuration "prefix": "test123" returns the name test123-arm-1.
On your machine’s CONFIGURE tab, switch to JSON mode and add a prefix to the fragment object:
{
"components": [ ... ],
"services": [ ... ],
"modules": [ ... ],
"fragments": [
{
"id": "0a44e14b-ec43-40e7-9641-1f593072e281",
"prefix": "hello-world-mlresources"
}
]
}
Example fragments
For an example of a fragment that configures multiple components and services, see the Viam Rover fragment.
For an example of creating a fragment and using it to configure a fleet of machines, see the air quality fleet tutorial.
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!