Schema mapping reference
The schema mapping section of a sync project's config.yml defines how data translates between the source system and the destination system. Worked examples for NetBox β Infrahub and Nautobot β Infrahub appear at the end.
For the full configuration schema (not just the mapping section), see Sync instance configuration.
Anatomy of a schema mappingβ
Each entry in the schema_mapping section maps one model from the source system to one model in the destination system. A mapping entry contains:
- Name β the destination model name.
- Mapping β the source model name in the source system.
- Identifiers β the field(s) that uniquely identify an object in this model.
- Fields β the per-field mappings between source and destination.
A minimal example:
schema_mapping:
- name: Device
mapping: dcim.device
identifiers: ["name"]
fields:
- name: name
mapping: name
- name: serial
mapping: serial
- name: status
mapping: status.value
This says: for each dcim.device in the source system, create or update a Device object in the destination using the name field as the unique identifier, and map the name, serial, and status.value fields directly.
Field mappingsβ
Each entry in the fields list defines one field mapping. The most common patterns are direct mapping, nested attribute mapping, static values, and references to other models.
Direct field mappingβ
The source field name maps directly to the destination field name:
- name: name
mapping: name
This is the most common case. The destination field name gets the value of the source field name.
Renaming fieldsβ
When the destination field has a different name than the source field, list them separately:
- name: device_role
mapping: role.slug
The destination field device_role gets the value of the source's role.slug.
Nested attribute mappingβ
For source data with nested structure, use dotted notation to reach into the nested attribute:
- name: status
mapping: status.value
- name: site
mapping: site.slug
- name: primary_ip
mapping: primary_ip4.address
Static valuesβ
When a destination field should always be set to the same value regardless of source data, use static:
- name: source_system
static: netbox
This is useful for fields that record provenance, type discriminators, or any field where the value is determined by the sync configuration rather than the source data.
References to other modelsβ
When a destination field is a relationship to another model that is also being synced, use reference to point to that model:
- name: device
mapping: device.name
reference: Device
This says: the value of the source's device.name field should resolve to the Device object with that name in the destination. The referenced model must be synced before this one β see the order key in the project configuration.
Identifiersβ
The identifiers list defines which field(s) uniquely identify an object of this model. Identifiers are used to determine whether an object already exists in the destination and should be updated, or whether a new object should be created.
Single-field identifiersβ
For most models, a single field β typically name β is enough:
identifiers: ["name"]
Composite identifiersβ
Some models need multiple fields to be uniquely identified. For example, an IP address is unique by address plus VRF:
identifiers: ["address", "vrf"]
All listed fields must be present and unique together. Each identifier field must also be mapped in the fields list.
Filtersβ
Filters control which objects from the source get synced. Apply them at the model level to include or exclude specific objects.
- name: Device
mapping: dcim.device
identifiers: ["name"]
filters:
- field: status.value
operation: "=="
value: active
fields:
- name: name
mapping: name
This syncs only devices with status.value == "active". Other devices are skipped.
Available filter operationsβ
Infrahub Sync supports the following 14 filter operations:
| Operation | Description |
|---|---|
== | Equal to the value |
!= | Not equal to the value |
> | Greater than (numeric) |
< | Less than (numeric) |
>= | Greater than or equal (numeric) |
<= | Less than or equal (numeric) |
in | Value is in a list or string |
not in | Value is not in a list or string |
contains | Field value contains the given value |
not contains | Field value does not contain the given value |
is_empty | Field is None or empty (no value argument needed) |
is_not_empty | Field is not None and not empty (no value argument needed) |
regex | Field matches the regular expression in value |
is_ip_within | Field (an IP address) is within the IP range in value |
Multiple filters on the same model are combined with AND β an object must match all filters to be included.