Network as code
The design is the data. The config is a build artifact.
network-as-code/ in this repository is a small, runnable example: a two-site
VXLAN BGP EVPN fabric and a DMVPN Phase 3 hub and spoke. Ansible renders IOS-XE and NX-OS
from YAML. Tests check the result. Nothing logs into a router.
- Lint yamllint on the source of truth, the playbook, and the inventory.
- Render
ansible-playbook playbooks/render.ymlwritesrendered/. - Test Pytest checks peers, VNIs, NHRP roles, per-spoke filters, and that no real key is present.
What the data describes
The fabric is two sites, each with two spines, two leaf VTEPs, and two border gateways. Spines reflect EVPN routes. Leaves share an anycast gateway. Border gateways peer eBGP across DCI and rewrite route targets. The DMVPN example is one hub and two spokes, IKEv2, a front-door VRF, named EIGRP, and a per-spoke inbound filter so a spoke can only inject its own LAN.
The pre-shared key in the rendered IOS-XE is the placeholder REDACTED-FROM-VAULT.
A real key would come from Ansible Vault at deploy time. It is not in this repository.
Optional live collection via Netmiko reads credentials from the environment and is not
called by CI.
Source of truth
network-as-code/data/fabric.yml
---
# Source of truth for a two-site VXLAN BGP EVPN fabric.
# Render with: ansible-playbook playbooks/render.yml
name: mesa-multisite
anycast_gateway_mac: "0000.2222.3333"
ospf_process: UNDERLAY
ospf_area: "0.0.0.0"
mtu: 9216
sites:
- id: a
name: site-a
asn: 65011
multisite_id: 65011
multisite_vip: "10.100.1.1"
- id: b
name: site-b
asn: 65012
multisite_id: 65012
multisite_vip: "10.100.2.1"
vrfs:
- name: APP
vni: 50001
vlan: 901
vnis:
- id: 10010
vlan: 10
name: APP-WEB
type: l2
vrf: APP
gateway: "10.10.10.1"
prefix: 24
- id: 10020
vlan: 20
name: APP-DB
type: l2
vrf: APP
gateway: "10.20.20.1"
prefix: 24
- id: 50001
vlan: 901
name: APP-L3
type: l3
vrf: APP
devices:
- hostname: spine-a1
role: spine
site: a
router_id: "10.0.0.11"
# … devices, links, and host ports follow rendered/nxos/leaf-a1.cfg
! Generated by network-as-code from data/fabric.yml
! Do not edit by hand. Re-render with playbooks/render.yml.
!
hostname leaf-a1
!
feature ospf
feature bgp
feature interface-vlan
feature vn-segment-vlan-based
feature nv overlay
nv overlay evpn
fabric forwarding anycast-gateway-mac 0000.2222.3333
vlan 10
name APP-WEB
vn-segment 10010
vlan 20
name APP-DB
vn-segment 10020
vlan 901
name APP-L3
vn-segment 50001
vrf context APP
vni 50001
rd auto
address-family ipv4 unicast
route-target both auto
route-target both auto evpn
interface loopback0
description router-id
ip address 10.0.0.21/32
ip router ospf UNDERLAY area 0.0.0.0
interface loopback1
description vtep
ip address 10.1.1.21/32
ip router ospf UNDERLAY area 0.0.0.0
interface Ethernet1/1
description spine-a1
no switchport
mtu 9216
no shutdown
ip address 10.1.11.1/31
ip ospf network point-to-point
no ip ospf passive-interface
ip router ospf UNDERLAY area 0.0.0.0
interface Ethernet1/2
description spine-a2
no switchport
mtu 9216
no shutdown
ip address 10.1.12.1/31
ip ospf network point-to-point
no ip ospf passive-interface
ip router ospf UNDERLAY area 0.0.0.0
interface Ethernet1/10
description app web server
switchport
switchport mode access
switchport access vlan 10
spanning-tree port type edge
no shutdown
interface Ethernet1/11
description app db server
switchport
switchport mode access
switchport access vlan 20
spanning-tree port type edge
no shutdown
interface Vlan10
description anycast-gateway APP-WEB
no shutdown
vrf member APP
ip address 10.10.10.1/24
fabric forwarding mode anycast-gateway
interface Vlan20
description anycast-gateway APP-DB
no shutdown
vrf member APP
ip address 10.20.20.1/24
fabric forwarding mode anycast-gateway
interface nve1
no shutdown
host-reachability protocol bgp
source-interface loopback1
member vni 10010
ingress-replication protocol bgp
member vni 10020
ingress-replication protocol bgp
member vni 50001 associate-vrf
evpn
vni 10010 l2
rd auto
route-target import auto
route-target export auto
vni 10020 l2
rd auto
route-target import auto
route-target export auto
router ospf UNDERLAY
router-id 10.0.0.21
passive-interface default
router bgp 65011
router-id 10.0.0.21
address-family ipv4 unicast
address-family l2vpn evpn
neighbor 10.0.0.11
remote-as 65011
description spine-a1
update-source loopback0
address-family l2vpn evpn
send-community
send-community extended
neighbor 10.0.0.12
remote-as 65011
description spine-a2
update-source loopback0
address-family l2vpn evpn
send-community
send-community extended
!
end rendered/iosxe/hub-den1.cfg
! Generated by network-as-code from data/dmvpn.yml
! Do not edit by hand. Re-render with playbooks/render.yml.
! The pre-shared key below is a placeholder. Supply the real key from Ansible Vault
! at deploy time. This repository does not contain a usable key.
!
hostname hub-den1
!
vrf definition WAN
address-family ipv4
exit-address-family
!
vrf definition CORP
address-family ipv4
exit-address-family
!
crypto ikev2 proposal DMVPN-PROPOSAL
encryption aes-gcm-256
prf sha256
group 19
!
crypto ikev2 policy DMVPN-POLICY
proposal DMVPN-PROPOSAL
!
crypto ikev2 keyring DMVPN-KEYRING
peer ANY
address 0.0.0.0 0.0.0.0
pre-shared-key REDACTED-FROM-VAULT
!
crypto ikev2 profile DMVPN-IKEPROF
match fvrf WAN
match identity remote address 0.0.0.0
authentication remote pre-share
authentication local pre-share
keyring local DMVPN-KEYRING
dpd 40 5 on-demand
ivrf CORP
!
crypto ipsec transform-set DMVPN-TS esp-gcm 256
mode transport
!
crypto ipsec profile DMVPN-IPSEC
set transform-set DMVPN-TS
set ikev2-profile DMVPN-IKEPROF
!
ip prefix-list PFX-spoke-north seq 10 permit 10.11.0.0/24
ip prefix-list GW-spoke-north seq 10 permit 10.255.101.11/32
ip prefix-list PFX-spoke-south seq 10 permit 10.12.0.0/24
ip prefix-list GW-spoke-south seq 10 permit 10.255.101.12/32
!
interface GigabitEthernet1
description WAN underlay in WAN
vrf forwarding WAN
ip address 203.0.113.11 255.255.255.0
no shutdown
!
interface GigabitEthernet2
description CORP LAN
vrf forwarding CORP
ip address 10.1.0.1 255.255.255.0
no shutdown
!
interface Tunnel0
description DMVPN phase 3 hub
vrf forwarding CORP
ip address 10.255.101.1 255.255.255.0
no ip redirects
ip mtu 1400
ip tcp adjust-mss 1360
ip nhrp network-id 101
ip nhrp authentication REDACTED-FROM-VAULT
ip nhrp holdtime 600
ip nhrp map multicast dynamic
ip nhrp redirect
tunnel source GigabitEthernet1
tunnel mode gre multipoint
tunnel vrf WAN
tunnel protection ipsec profile DMVPN-IPSEC
!
ip route vrf WAN 0.0.0.0 0.0.0.0 203.0.113.1
!
router eigrp OVERLAY
address-family ipv4 unicast vrf CORP autonomous-system 101
af-interface default
passive-interface
exit-af-interface
af-interface Tunnel0
no passive-interface
no next-hop-self
no split-horizon
exit-af-interface
topology base
distribute-list prefix PFX-spoke-north gateway GW-spoke-north in
distribute-list prefix PFX-spoke-south gateway GW-spoke-south in
exit-af-topology
network 10.255.101.0 0.0.0.255
network 10.1.0.0 0.0.0.255
exit-address-family
!
end Run it locally
cd network-as-code
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
yamllint .
ansible-playbook playbooks/render.yml
pytest
python -m nac.validate
The same three steps run in GitHub Actions on every change under network-as-code/.
Details, the data model, and what is deliberately absent are in
network-as-code/README.md.