Skip to content

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:

  1. inventory — calls sync_device_inventory
  2. prefixes — calls sync_device_prefixes
  3. interfaces — calls sync_device_interfaces
  4. vrfs — calls sync_vrfs
  5. vlans — calls sync_vlans
  6. ip_addresses — calls sync_device_ip
  7. vrrp — calls sync_vrrp
  8. bgp_communities - calls sync_bgp_community
  9. bgp_peerings — calls sync_bgp_peerings

How It Works¤

The sync_all task orchestrates nine 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. If VLAN synchronization fails, sync_all returns immediately and does not run IP address, VRRP, BGP community, or BGP peering synchronization.

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_device_prefixes:
  ignore_vrf: true
  ignore_site: true

sync_vrfs:
  device_custom_field: devices
  interface_map: nf://netbox/interface_map.yaml

sync_device_interfaces:
  process_deletions: true
  interface_map: nf://netbox/interface_map.yaml

sync_vlans:
  filter_by_vlan_ids:
    - 100-299
  interface_map: nf://netbox/interface_map.yaml
  vlan_map: nf://netbox/vlan_map.yaml

sync_bgp_community:
  community_name_field: community_name

sync_device_ip:
  ignore_vrf: false
  ignore_ranges:
    - 192.0.2.0/24

sync_vrrp:
  name_template: "{{ device }}-{{ interface }}-vrrp-{{ group_id }}"

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_bgp_community, sync_device_ip, sync_vrrp, 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¤

Both coordinated tasks include inventory, prefixes, interfaces, VRFs, VLANs, IP addresses, VRRP, BGP communities, and BGP peerings. Every selected device has all nine category keys. Disabled categories are None; failed categories are False. Sync results contain child task summaries or dry-run previews, while checks return booleans for drift state. The diff dictionary retains child dry-run details under the same category keys, with None for unexecuted checks or stages. MAC synchronization is available through its standalone task.

The result structure aggregates the outcomes of all nine 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. The VLAN category retains separate object and interfaces sections. The VRF category retains separate vrfs, route_targets, routing_policies, and interfaces sections. Each interfaces section contains only the current device.

{
    # per-device results — one entry per resolved device
    "result": {
        "ceos-spine-1": {
            "inventory": {
                "created": [ ... ],
                "updated": [ ... ],
                "deleted": [ ... ],
                "in_sync": [ ... ],
            },
            "vlans": {
                "vlans": {
                    "site:DC1": {
                        "create": [ ... ],
                        "update": { ... },
                        "delete": [],
                        "in_sync": [ ... ],
                    },
                },
                "interfaces": {
                    "ceos-spine-1": {
                        "create": [],
                        "update": { ... },
                        "delete": [],
                        "in_sync": [ ... ],
                    },
                },
            },
            "prefixes": {
                "created": [ ... ],
                "updated": [ ... ],
                "in_sync": [ ... ],
            },
            "vrfs": {
                "vrfs": {
                    "create": [ ... ],
                    "update": { ... },
                    "delete": [],
                    "in_sync": [ ... ],
                },
                "route_targets": {
                    "create": [ ... ],
                    "update": {},
                    "delete": [],
                    "in_sync": [],
                },
                "routing_policies": {
                    "create": [ ... ],
                    "update": {},
                    "delete": [],
                    "in_sync": [],
                },
                "interfaces": {
                    "ceos-spine-1": {
                        "create": [],
                        "update": { ... },
                        "delete": [],
                        "in_sync": [ ... ],
                    },
                },
            },
            "interfaces": {
                "create":  { ... },
                "update":  { ... },
                "delete":  { ... },
                "in_sync": [ ... ],
            },
            "bgp_communities": {"route_targets": {}, "communities": {}},
            "ip_addresses": {
                "created": [ ... ],
                "updated": [ ... ],
                "in_sync": [ ... ],
            },
            "vrrp": {
                "created": [ ... ],
                "updated": [ ... ],
                "deleted": [ ... ],
                "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 nine 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_device_prefixes": {"ignore_vrf": True},
            "sync_vrfs": {
                "device_custom_field": "devices",
                "interface_map": "nf://netbox/interface_map.yaml",
            },
            "sync_device_interfaces": {
                "interface_map": "nf://netbox/interface_map.yaml",
            },
            "sync_vlans": {
                "filter_by_vlan_ids": ["100-299"],
                "interface_map": "nf://netbox/interface_map.yaml",
                "vlan_map": "nf://netbox/vlan_map.yaml",
            },
            "sync_device_ip": {"ignore_vrf": False},
            "sync_vrrp": {"name_template": "{{ device }}-{{ interface }}-vrrp-{{ group_id }}"},
            "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, prefixes, interfaces, VRFs, VLANs, IP addresses, VRRP, BGP communities 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, prefixes, interfaces, VRFs, VLANs, IP addresses, VRRP, BGP communities, and 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":         {
            "vlans": {"<scope>": {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]}},
            "interfaces": {"<device>": {"created": [], "updated": [...], "deleted": [], "in_sync": [...]}},
        },
        "prefixes":      {"created": [...], "updated": [...], "in_sync": [...]},
        "vrfs":          {
            "vrfs": {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]},
            "route_targets": {"created": [...], "updated": [], "deleted": [], "in_sync": []},
            "routing_policies": {"created": [...], "updated": [], "deleted": [], "in_sync": []},
            "interfaces": {"<device>": {"created": [], "updated": [...], "deleted": [], "in_sync": [...]}},
        },
        "interfaces":    {"created": [...], "updated": {...}, "deleted": [...], "in_sync": [...]},
        "ip_addresses":  {"created": [...], "updated": [...], "in_sync": [...]},
        "vrrp":          {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]},
        "bgp_communities": {"route_targets": {...}, "communities": {...}},
        "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 600.

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 nf:// YAML file containing that dictionary. Set a task key to False to skip that task.

None
**kwargs Any

Nornir host filter arguments (e.g. FL, FC, FB).

{}

Returns:

Name Type Description
Result Result

Per-device results with all nine category keys. Successful

Result

sections contain child task results, including previews in dry-run

Result

mode; failed sections are False and skipped or unexecuted sections

Result

are None. Diff contains child diffs keyed by category, with None for

Result

unexecuted stages. Errors and failed resources are propagated.

Result

Execution stops on a failed stage or declined review.

Source code in norfab\workers\netbox_worker\devices_tasks.py
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
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
@Task(
    fastapi={"methods": ["POST"], "schema": NetboxFastApiArgs.model_json_schema()},
    input=SyncAllInput,
    output=SyncAllResult,
    mcp={
        "annotations": {
            "title": "Sync All Device Data",
            "readOnlyHint": False,
            "destructiveHint": True,
            "idempotentHint": True,
            "openWorldHint": True,
        }
    },
)
def sync_all(
    self,
    job: Job,
    instance: Union[None, str] = None,
    timeout: int = 600,
    devices: Union[None, list] = None,
    branch: str = None,
    dry_run: bool = False,
    with_approval: bool = False,
    sync_kwargs: Union[None, dict, str] = None,
    **kwargs: Any,
) -> Result:
    """
    Synchronize all device data from live devices into NetBox in sequence:
    inventory, prefixes, interfaces, VRFs, VLANs, IP addresses, VRRP,
    BGP communities, and 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":         {
                    "vlans": {"<scope>": {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]}},
                    "interfaces": {"<device>": {"created": [], "updated": [...], "deleted": [], "in_sync": [...]}},
                },
                "prefixes":      {"created": [...], "updated": [...], "in_sync": [...]},
                "vrfs":          {
                    "vrfs": {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]},
                    "route_targets": {"created": [...], "updated": [], "deleted": [], "in_sync": []},
                    "routing_policies": {"created": [...], "updated": [], "deleted": [], "in_sync": []},
                    "interfaces": {"<device>": {"created": [], "updated": [...], "deleted": [], "in_sync": [...]}},
                },
                "interfaces":    {"created": [...], "updated": {...}, "deleted": [...], "in_sync": [...]},
                "ip_addresses":  {"created": [...], "updated": [...], "in_sync": [...]},
                "vrrp":          {"created": [...], "updated": [...], "deleted": [...], "in_sync": [...]},
                "bgp_communities": {"route_targets": {...}, "communities": {...}},
                "bgp_peerings":  {"create": [...],  "update": {...},  "delete": [...],  "in_sync": [...]},
            }
        }

    Args:
        job: NorFab Job object.
        instance (str, optional): NetBox instance name.
        timeout (int): Timeout in seconds for Nornir jobs. Defaults to 600.
        devices (list, optional): List of device names to sync.
        branch (str, optional): NetBox branching plugin branch name.
        dry_run (bool): If True, preview changes without writing to NetBox. Defaults to False.
        with_approval (bool): Preview and ask for review before applying
            each sync stage. Defaults to False.
        sync_kwargs: Per-task arguments keyed by sync task name, or an
            ``nf://`` YAML file containing that dictionary. Set a task key
            to ``False`` to skip that task.
        **kwargs: Nornir host filter arguments (e.g. ``FL``, ``FC``, ``FB``).

    Returns:
        Result: Per-device results with all nine category keys. Successful
        sections contain child task results, including previews in dry-run
        mode; failed sections are False and skipped or unexecuted sections
        are None. Diff contains child diffs keyed by category, with None for
        unexecuted stages. Errors and failed resources are propagated.
        Execution stops on a failed stage or declined review.
    """
    devices = devices or []
    instance = instance or self.default_instance
    if isinstance(sync_kwargs, str):
        sync_kwargs = yaml.safe_load(
            self.fetch_file(sync_kwargs, raise_on_fail=True)
        )
    sync_kwargs = sync_kwargs or {}
    ret = Result(
        task=f"{self.name}:sync_all",
        result={},
        resources=[instance],
        diff={},
        dry_run=dry_run,
    )

    # resolve devices from Nornir filters
    if kwargs:
        nornir_hosts = self.get_nornir_hosts(kwargs, timeout)
        for host in nornir_hosts:
            if host not in devices:
                devices.append(host)

    if not devices:
        ret.errors.append("no devices specified")
        ret.failed = True
        return ret

    log.info(
        f"{self.name} - Sync all for {len(devices)} device(s) in '{instance}', dry_run={dry_run}"
    )
    job.event(f"syncing all data for {len(devices)} device(s), dry_run={dry_run}")

    categories = (
        "inventory",
        "prefixes",
        "interfaces",
        "vrfs",
        "vlans",
        "ip_addresses",
        "vrrp",
        "bgp_communities",
        "bgp_peerings",
    )
    ret.diff = dict.fromkeys(categories)
    # initialize per-device result structure
    for device in devices:
        ret.result[device] = dict.fromkeys(categories)

    # --- sync device inventory ---
    if sync_kwargs.get("sync_device_inventory") is False:
        job.event("skipping device inventory sync")
    else:
        job.event("syncing device inventory")
        inventory_result = self.sync_device_inventory(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_device_inventory") or {}),
        )
        if inventory_result.errors:
            job.event("inventory sync completed with errors", severity="WARNING")
            ret.errors.extend(inventory_result.errors)
        ret.diff["inventory"] = inventory_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(inventory_result.resources_failed)
        )
        if inventory_result.failed and not inventory_result.resources_failed:
            for device in devices:
                ret.result[device]["inventory"] = False
            ret.failed = True
            job.event(
                "sync all stopped because device inventory sync failed",
                severity="ERROR",
            )
            return ret
        for device, data in inventory_result.result.items():
            ret.result.setdefault(device, {})["inventory"] = data
        for device in devices:
            if device in inventory_result.resources_failed:
                ret.result[device]["inventory"] = False
        if inventory_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if inventory_result.status == "skipped" and inventory_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event(
                "sync all stopped because device inventory review was declined"
            )
            return ret

    # --- sync prefixes ---
    if sync_kwargs.get("sync_device_prefixes") is False:
        job.event("skipping prefix sync")
    else:
        job.event("syncing prefixes")
        prefix_result = self.sync_device_prefixes(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_device_prefixes") or {}),
        )
        if prefix_result.errors:
            job.event("prefix sync completed with errors", severity="WARNING")
            ret.errors.extend(prefix_result.errors)
        ret.diff["prefixes"] = prefix_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(prefix_result.resources_failed)
        )
        if prefix_result.failed and not prefix_result.resources_failed:
            for device in devices:
                ret.result[device]["prefixes"] = False
            ret.failed = True
            job.event(
                "sync all stopped because prefix sync failed", severity="ERROR"
            )
            return ret
        for device in devices:
            ret.result[device]["prefixes"] = prefix_result.result
        for device in devices:
            if device in prefix_result.resources_failed:
                ret.result[device]["prefixes"] = False
        if prefix_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if prefix_result.status == "skipped" and prefix_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event("sync all stopped because prefix review was declined")
            return ret

    # --- sync interfaces before assigning them to VRFs ---
    if sync_kwargs.get("sync_device_interfaces") is False:
        job.event("skipping interface sync")
    else:
        job.event("syncing interfaces")
        intf_result = self.sync_device_interfaces(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_device_interfaces") or {}),
        )
        if intf_result.errors:
            job.event("interface sync completed with errors", severity="WARNING")
            ret.errors.extend(intf_result.errors)
        ret.diff["interfaces"] = intf_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(intf_result.resources_failed)
        )
        if intf_result.failed and not intf_result.resources_failed:
            for device in devices:
                ret.result[device]["interfaces"] = False
            ret.failed = True
            job.event(
                "sync all stopped because interface sync failed", severity="ERROR"
            )
            return ret
        for device, data in intf_result.result.items():
            ret.result.setdefault(device, {})["interfaces"] = data
        for device in devices:
            if device in intf_result.resources_failed:
                ret.result[device]["interfaces"] = False
        if intf_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if intf_result.status == "skipped" and intf_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event("sync all stopped because interface review was declined")
            return ret

    # --- sync VRFs and interface assignments ---
    if sync_kwargs.get("sync_vrfs") is False:
        job.event("skipping VRF sync")
    else:
        job.event("syncing VRFs")
        vrf_result = self.sync_vrfs(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_vrfs") or {}),
        )
        if vrf_result.errors:
            job.event("VRF sync completed with errors", severity="WARNING")
            ret.errors.extend(vrf_result.errors)
        ret.diff["vrfs"] = vrf_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(vrf_result.resources_failed)
        )
        if vrf_result.failed and not vrf_result.resources_failed:
            for device in devices:
                ret.result[device]["vrfs"] = False
            ret.failed = True
            job.event("sync all stopped because VRF sync failed", severity="ERROR")
            return ret
        for device in devices:
            device_interfaces = {}
            if device in vrf_result.result["interfaces"]:
                device_interfaces[device] = vrf_result.result["interfaces"][device]
            ret.result[device]["vrfs"] = {
                "vrfs": vrf_result.result["vrfs"],
                "route_targets": vrf_result.result["route_targets"],
                "routing_policies": vrf_result.result["routing_policies"],
                "interfaces": device_interfaces,
            }
        for device in devices:
            if device in vrf_result.resources_failed:
                ret.result[device]["vrfs"] = False
        if vrf_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if vrf_result.status == "skipped" and vrf_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event("sync all stopped because VRF review was declined")
            return ret

    # --- sync VLANs after interfaces exist ---
    if sync_kwargs.get("sync_vlans") is False:
        job.event("skipping VLAN sync")
    else:
        job.event("syncing VLANs")
        vlan_result = self.sync_vlans(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_vlans") or {}),
        )
        if vlan_result.errors:
            job.event("VLAN sync completed with errors", severity="WARNING")
            ret.errors.extend(vlan_result.errors)
        ret.diff["vlans"] = vlan_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(vlan_result.resources_failed)
        )
        if vlan_result.failed and not vlan_result.resources_failed:
            for device in devices:
                ret.result[device]["vlans"] = False
            ret.failed = True
            job.event("sync all stopped because VLAN sync failed", severity="ERROR")
            return ret
        for device in devices:
            device_interfaces = {}
            if device in vlan_result.result["interfaces"]:
                device_interfaces[device] = vlan_result.result["interfaces"][device]
            ret.result[device]["vlans"] = {
                "vlans": vlan_result.result["vlans"],
                "interfaces": device_interfaces,
            }
        for device in devices:
            if device in vlan_result.resources_failed:
                ret.result[device]["vlans"] = False
        if vlan_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if vlan_result.status == "skipped" and vlan_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event("sync all stopped because VLAN review was declined")
            return ret

    # --- sync IP addresses ---
    if sync_kwargs.get("sync_device_ip") is False:
        job.event("skipping IP address sync")
    else:
        job.event("syncing IP addresses")
        ip_result = self.sync_device_ip(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_device_ip") or {}),
        )
        if ip_result.errors:
            job.event("IP address sync completed with errors", severity="WARNING")
            ret.errors.extend(ip_result.errors)
        ret.diff["ip_addresses"] = ip_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(ip_result.resources_failed)
        )
        if ip_result.failed and not ip_result.resources_failed:
            for device in devices:
                ret.result[device]["ip_addresses"] = False
            ret.failed = True
            job.event(
                "sync all stopped because IP address sync failed", severity="ERROR"
            )
            return ret
        for device, data in ip_result.result.items():
            ret.result.setdefault(device, {})["ip_addresses"] = data
        for device in devices:
            if device in ip_result.resources_failed:
                ret.result[device]["ip_addresses"] = False
        if ip_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if ip_result.status == "skipped" and ip_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event("sync all stopped because IP address review was declined")
            return ret

    # --- sync VRRP after regular IP addresses ---
    if sync_kwargs.get("sync_vrrp") is False:
        job.event("skipping VRRP sync")
    else:
        job.event("syncing VRRP")
        vrrp_result = self.sync_vrrp(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_vrrp") or {}),
        )
        if vrrp_result.errors:
            job.event("VRRP sync completed with errors", severity="WARNING")
            ret.errors.extend(vrrp_result.errors)
        ret.diff["vrrp"] = vrrp_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(vrrp_result.resources_failed)
        )
        if vrrp_result.failed and not vrrp_result.resources_failed:
            for device in devices:
                ret.result[device]["vrrp"] = False
            ret.failed = True
            job.event("sync all stopped because VRRP sync failed", severity="ERROR")
            return ret
        for device, data in vrrp_result.result.items():
            ret.result.setdefault(device, {})["vrrp"] = data
        for device in devices:
            if device in vrrp_result.resources_failed:
                ret.result[device]["vrrp"] = False
        if vrrp_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if vrrp_result.status == "skipped" and vrrp_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event("sync all stopped because VRRP review was declined")
            return ret

    # --- sync BGP communities ---
    if sync_kwargs.get("sync_bgp_community") is False:
        job.event("skipping BGP community sync")
    else:
        job.event("syncing BGP communities")
        community_result = self.sync_bgp_community(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_bgp_community") or {}),
        )
        if community_result.errors:
            job.event(
                "bgp community sync completed with errors", severity="WARNING"
            )
            ret.errors.extend(community_result.errors)
        ret.diff["bgp_communities"] = community_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(community_result.resources_failed)
        )
        if community_result.failed and not community_result.resources_failed:
            for device in devices:
                ret.result[device]["bgp_communities"] = False
            ret.failed = True
            job.event(
                "sync all stopped because BGP community sync failed",
                severity="ERROR",
            )
            return ret
        for device in devices:
            ret.result[device]["bgp_communities"] = community_result.result
        for device in devices:
            if device in community_result.resources_failed:
                ret.result[device]["bgp_communities"] = False
        if community_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if community_result.status == "skipped" and community_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event("sync all stopped because BGP community review was declined")
            return ret

    # --- sync BGP peerings ---
    if sync_kwargs.get("sync_bgp_peerings") is False:
        job.event("skipping BGP peering sync")
    else:
        job.event("syncing BGP peerings")
        bgp_result = self.sync_bgp_peerings(
            job=job,
            instance=instance,
            dry_run=dry_run,
            timeout=timeout,
            devices=list(devices),
            branch=branch,
            with_approval=with_approval,
            **(sync_kwargs.get("sync_bgp_peerings") or {}),
        )
        if bgp_result.errors:
            job.event("BGP peerings sync completed with errors", severity="WARNING")
            ret.errors.extend(bgp_result.errors)
        ret.diff["bgp_peerings"] = bgp_result.diff
        ret.resources_failed = sorted(
            set(ret.resources_failed) | set(bgp_result.resources_failed)
        )
        if bgp_result.failed and not bgp_result.resources_failed:
            for device in devices:
                ret.result[device]["bgp_peerings"] = False
            ret.failed = True
            job.event(
                "sync all stopped because BGP peering sync failed", severity="ERROR"
            )
            return ret
        for device, data in bgp_result.result.items():
            ret.result.setdefault(device, {})["bgp_peerings"] = data
        for device in devices:
            if device in bgp_result.resources_failed:
                ret.result[device]["bgp_peerings"] = False
        if bgp_result.failed:
            ret.failed = True
            job.event(
                "sync all stopped because a sync stage failed", severity="ERROR"
            )
            return ret
        if bgp_result.status == "skipped" and bgp_result.dry_run:
            ret.status = "skipped"
            ret.dry_run = True
            job.event("sync all stopped because BGP peerings review was declined")
            return ret

    log.info(f"{self.name} - Sync all complete for {len(ret.result)} device(s)")
    job.event(f"sync all complete for {len(ret.result)} device(s)")
    return ret