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 - prefixes — calls
sync_device_prefixes - interfaces — calls
sync_device_interfaces - vrfs — calls
sync_vrfs - vlans — calls
sync_vlans - ip_addresses — calls
sync_device_ip - vrrp — calls
sync_vrrp - bgp_communities - calls
sync_bgp_community - 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
|
None
|
**kwargs
|
Any
|
Nornir host filter arguments (e.g. |
{}
|
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 | |