Netbox Sync All Task¤
task api name:
sync_all
The sync_all task synchronizes device data from live devices into NetBox in a
fixed sequence:
- inventory — calls
sync_device_inventory - vlans — calls
sync_vlans - prefixes — calls
sync_device_prefixes - vrfs — calls
sync_vrfs - interfaces — calls
sync_device_interfaces - mac_addresses — calls
sync_mac_addresses - ip_addresses — calls
sync_device_ip - bgp_peerings — calls
sync_bgp_peerings
How It Works¤
The sync_all task orchestrates eight subordinate sync tasks in sequence. Each task collects live device data,
compares it against NetBox state, and applies reconciliation operations. When dry_run=True, all tasks preview changes
without writing. When with_approval=True, each stage waits for user confirmation before applying changes.
Execution Modes¤
Dry-run mode (dry_run=True) previews all changes without writing to NetBox.
With Approval — Pass with_approval=True to use the interactive NFCLI workflow. Each sync stage displays its preview, and waits for review before applying that stage. Declining a stage stops sync_all at that point, returns the declined dry-run result, and skips later stages. Any earlier approved stages remain applied.
Note
When both dry-run and with_approval are True, dry-run logic ignored.
Live-run mode (dry_run=False, default) applies all changes to NetBox.
Sync Task Arguments¤
Use sync_kwargs to pass arguments to individual sync tasks. It accepts an
inline dictionary, an nf:// URL to a YAML file containing that dictionary, or
None. The dictionary keys are task API names and each value is passed to that
task as keyword arguments:
sync_device_inventory:
create_module_types: true
create_module_bays: true
inventory_map: nf://netbox/inventory_maps/iosxr.yaml
message: sync all device data
sync_vlans:
filter_by_vlan_ids:
- 100-299
sync_device_prefixes:
ignore_vrf: true
ignore_site: true
sync_vrfs:
device_custom_field: devices
sync_device_interfaces:
process_deletions: true
interface_map: nf://netbox/interface_map.yaml
vlan_map: nf://netbox/vlan_map.yaml
sync_mac_addresses:
filter_by_name: Ethernet*
sync_device_ip:
ignore_vrf: false
ignore_ranges:
- 192.0.2.0/24
sync_bgp_peerings:
process_deletions: true
status: active
message: sync all device data
The supported keys are sync_device_inventory, sync_vlans,
sync_device_prefixes, sync_vrfs, sync_device_interfaces,
sync_mac_addresses, sync_device_ip, and sync_bgp_peerings. Refer to each
task's documentation for its accepted arguments. Missing keys run with the
subordinate task's defaults. Set a key to false to skip that task and continue
with the next stage:
sync_device_interfaces: false
Skipped tasks are omitted from each device's result categories.
Keep instance, timeout, devices, branch, dry_run, and with_approval
at the sync_all level rather than repeating them inside a task dictionary.
Output¤
The result structure aggregates the outcomes of all eight subordinate sync tasks. When dry_run=True the same structure is returned but no changes are written to NetBox. VLAN, prefix, and VRF results describe shared NetBox objects, so the same shared result is included under each selected device.
{
# per-device results — one entry per resolved device
"result": {
"ceos-spine-1": {
"inventory": {
"created": [ ... ],
"updated": [ ... ],
"deleted": [ ... ],
"in_sync": [ ... ],
},
"vlans": {
"site:DC1": {
"create": [ ... ],
"update": { ... },
"delete": [],
"in_sync": [ ... ],
},
},
"prefixes": {
"created": [ ... ],
"updated": [ ... ],
"in_sync": [ ... ],
},
"vrfs": {
"global": {
"create": [ ... ],
"update": { ... },
"delete": [],
"in_sync": [ ... ],
},
},
"interfaces": {
"create": { ... },
"update": { ... },
"delete": { ... },
"in_sync": [ ... ],
},
"mac_addresses": {
"created": [ ... ],
"updated": [ ... ],
"in_sync": [ ... ],
},
"ip_addresses": {
"created": [ ... ],
"updated": [ ... ],
"in_sync": [ ... ],
},
"bgp_peerings": {
"create": { ... },
"update": { ... },
"delete": { ... },
"in_sync": [ ... ],
},
},
...
},
"diff": {},
}
When dry_run=True the same structure is returned but no changes are written to NetBox.
Examples¤
Preview all eight sync categories:
nf#netbox sync all devices ceos-spine-1 ceos-spine-2 dry-run
Preview, prompt for review, and apply the changes:
nf#netbox sync all devices ceos-spine-1 ceos-spine-2 with-approval
Load per-task arguments from the File Sharing service:
nf#netbox sync all devices iosxr1 sync-kwargs nf://netbox/sync_all_kwargs.yaml dry-run
result = client.run_job(
"netbox",
"sync_all",
workers="any",
kwargs={
"devices": ["iosxr1"],
"dry_run": True,
"sync_kwargs": {
"sync_device_inventory": {
"create_module_bays": True,
"create_module_types": True,
"inventory_map": "nf://netbox/inventory_maps/iosxr.yaml",
},
"sync_vlans": {"filter_by_vlan_ids": ["100-299"]},
"sync_device_prefixes": {"ignore_vrf": True},
"sync_vrfs": {"device_custom_field": "devices"},
"sync_device_interfaces": {
"interface_map": "nf://netbox/interface_map.yaml",
"vlan_map": "nf://netbox/vlan_map.yaml",
},
"sync_device_ip": {"ignore_vrf": False},
"sync_bgp_peerings": False,
},
},
)
The same configuration can be stored in YAML and referenced with
"sync_kwargs": "nf://netbox/sync_all_kwargs.yaml".
NORFAB Netbox Sync All Command Shell Reference¤
NorFab shell supports these command options for Netbox sync_all task:
nf# man tree netbox.sync.all
root
└── netbox: Netbox service
└── sync: Sync Netbox data
└── all: Sync inventory, VLANs, prefixes, VRFs, interfaces, MAC addresses, IP addresses and BGP peerings
├── timeout: Job timeout
├── workers: Filter worker to target, default 'any'
├── verbose-result: Control output details, default 'False'
├── progress: Display progress events, default 'True'
├── instance: Netbox instance name to target
├── branch: Branching plugin branch name to use
├── devices: List of NetBox devices to sync all data for
├── dry-run: Return diff without writing to NetBox, default 'False'
├── with-approval: Preview each sync stage and ask for review before writing to NetBox
├── sync-kwargs: Per-task sync arguments or nf:// YAML file
├── FO: Filter hosts using Filter Object
├── FB: Filter hosts by name using Glob Patterns
├── FH: Filter hosts by hostname
├── FC: Filter hosts containment of pattern in name
├── FR: Filter hosts by name using Regular Expressions
├── FG: Filter hosts by group
├── FP: Filter hosts by hostname using IP Prefix
├── FL: Filter hosts by names list
├── FX: Filter hosts excluding them by name
└── FN: Negate the match
nf#
Python API Reference¤
Synchronize all device data from live devices into NetBox in sequence: inventory → VLANs → prefixes → VRFs → interfaces → MAC addresses → IP addresses → BGP peerings.
Pass dry_run=True to preview changes without writing to NetBox.
Pass with_approval=True to have each sync stage run a dry-run preview,
ask the interactive client for review, and only then apply that stage.
Result.result is keyed by device name, then by category::
{
"<device>": {
"inventory": {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]},
"vlans": {"<scope>": {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]}},
"prefixes": {"created": [...], "updated": [...], "in_sync": [...]},
"vrfs": {"global": {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]}},
"interfaces": {"created": [...], "updated": {...}, "deleted": [...], "in_sync": [...]},
"mac_addresses": {"created": [...], "updated": [...], "in_sync": [...]},
"ip_addresses": {"created": [...], "updated": [...], "in_sync": [...]},
"bgp_peerings": {"create": [...], "update": {...}, "delete": [...], "in_sync": [...]},
}
}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab Job object. |
required |
instance
|
str
|
NetBox instance name. |
None
|
timeout
|
int
|
Timeout in seconds for Nornir jobs. Defaults to 60. |
600
|
devices
|
list
|
List of device names to sync. |
None
|
branch
|
str
|
NetBox branching plugin branch name. |
None
|
dry_run
|
bool
|
If True, preview changes without writing to NetBox. Defaults to False. |
False
|
with_approval
|
bool
|
Preview and ask for review before applying each sync stage. Defaults to False. |
False
|
sync_kwargs
|
Union[None, dict, str]
|
Per-task arguments keyed by sync task name, or an
|
None
|
**kwargs
|
Any
|
Nornir host filter arguments (e.g. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Per-device sync results keyed by device name and category. |
Source code in norfab\workers\netbox_worker\devices_tasks.py
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 | |