Skip to main content

netmodel

Network data model generator — extract OpenConfig-based YAML from live networks via gNMI.

What it does

Connect to network devices via gNMI and export their configuration to a clean, vendor-agnostic YAML data model. This YAML becomes your source of truth for Infrastructure as Code (IaC) workflows.

Live Network → netmodel export → YAML Data Model → Ansible / IaC Tools

Installation

go install github.com/ndtobs/netmodel/cmd/netmodel@latest

Or build from source:

git clone https://github.com/ndtobs/netmodel
cd netmodel
go build -o netmodel ./cmd/netmodel

Quick Start

Export from all devices with Ansible structure and deduplication:

netmodel export @all -i inventory.yaml -o ./network-model/ --structure ansible --dedup

Output:

network-model/
├── group_vars/
│   ├── all.yaml          # Config common to ALL devices
│   ├── spine.yaml        # Config common to spines
│   └── leaf.yaml         # Config common to leaves
└── host_vars/
    ├── spine1/
    │   ├── bgp.yaml      # Device-specific only
    │   └── interfaces.yaml
    └── leaf1/
        └── ...

Export from a single device:

netmodel export 10.0.0.1:6030 -u admin -P password -k -o spine1/

Deduplication

The --dedup flag analyzes all exported configs and extracts common configuration:

OutputContains
group_vars/all.yamlConfig identical across ALL devices (NTP, DNS, AAA)
group_vars/<group>.yamlConfig identical within groups (peer groups, policies)
host_vars/<device>/Device-specific only (router-id, neighbors, interfaces)

Before dedup: Same peer groups, NTP servers, and policies duplicated in every host file.

After dedup: Common config in group_vars/, host files contain only what’s unique.

This follows Ansible best practices — change NTP servers once in group_vars/all.yaml, not in 50 host files.

Full dedup documentation

Exporters

FeatureDescription
interfacesIPs, descriptions, MTU, ethernet, LAG
bgpGlobal config, peer groups, neighbors, AFI/SAFI
ospfAreas, interfaces, timers
systemHostname, NTP, DNS, AAA/users, syslog
routing_policyPrefix-sets, community-sets, policies
evpnVTEP, VLAN-VNI, VRF-VNI mappings

Exporter details

CLI Reference

netmodel export <target> [flags]

Flags:
  -u, --username string    gNMI username
  -P, --password string    gNMI password
  -k, --insecure           skip TLS verification
  -f, --features strings   features to export (default: all)
  -o, --output string      output path (file or directory)
  -i, --inventory string   inventory file for @group targets
  -s, --structure string   output structure: flat, ansible (default: flat)
      --dedup              extract common config to group_vars (requires --structure ansible)
      --no-split           single file per device (default: split per-feature)
  -t, --timeout duration   gNMI timeout (default: 30s)

Try It

Use the network-labs EVPN topology:

git clone https://github.com/ndtobs/network-labs.git
cd network-labs/evpn-spine-leaf
sudo clab deploy -t topology.yaml

# Wait ~90s, then export
netmodel export @all -i inventory.yaml -o ./model/ --structure ansible --dedup

# See the results
tree ./model/
cat ./model/group_vars/leaf.yaml

Next Steps