This repo contains the examples and scripts from the Packet Coders webinar:
Automating Config Generation /w NetBox, Nornir and GraphQL
Note
The recording for the webinar session can be viewed here.
This demo will:
- Use NetBox as dynamic inventory.
- Pull down host and interface data from NetBox via GraphQL.
- Render the a basic device config using Jinja templating and the GraphQL data.
- Write the rendered configuration to a file.
- Clone repo:
git clone [email protected]:packetcoders/netbox-nornir-graphql-webinar.git
- Create a
.env
.
cp .env.example .env
- Populate
.env
with NetBox FQDN and API token. - Create virtual environment.
python -m venv .venv
source .venv/bin/activate
- Install dependancies
python -m pip install -r requirements.txt
./demo/nr_build_w_graphql.py
# Output:
# ./demo/nr_build_w_graphql.py
# Build Configs /w NB + GraphQL**************************************************
# *
# * leaf1 ** changed : False *************************************************
# ****
# vvvv Build Configs /w NB + GraphQL ** changed : False vvvvvvvvvvvvvvvvvvvvvv
# vvvv INFO
# ---- task_graphql ** changed : False ---------------------------------------
# ---- INFO
# { 'custom_fields': { 'domain_name': 'packetcoders.lab',
# 'ospf_area': '0',
# 'router_id': '1.1.1.1'},
# 'device_type': {'model': 'Cisco IOSv', 'slug': 'cisco-iosv'},
# 'interfaces': [ { 'ip_addresses': [{'address': '10.1.1
# .2/30'}],
# 'name': 'GigabitEthernet0/0'},
# { 'ip_addresses': [{'address': '10.2.1.2/30'}],
# 'name': 'GigabitEthernet0/1'},
# { 'ip_addresses': [{'address': '172.29.151.103/24'}]
# ,
# 'name': 'GigabitEthernet0/2'},
# {'ip_addresses': [], 'name': 'GigabitEthernet0/3'},
# {'ip_addresses': [], 'name': 'GigabitEthernet0/4'},
# {'ip_addresses': [], 'name': 'GigabitEthernet0/5'},
# {'ip_addresses': [], 'name': 'GigabitEthernet0/6'},
# {'ip_addresses': [], 'name': 'GigabitEthernet0/7'},
# {'ip_addresses': [], 'name': 'GigabitEthernet0/8'},
# {'ip_addresses': [], 'name': 'GigabitEthernet0/9'},
# { 'ip_addresses': [{'address': '1.1.1.1/32'}],
# 'name': 'Loopback 0'}],
...
The rendered files can then be located within the rendered directory:
head -n 20 demo/rendered/leaf1.txt
# Output:
# service timestamps debug datetime msec
# service timestamps log datetime msec
# no service password-encryption
#
# hostname leaf1
#
# boot-start-marker
# boot-end-marker
#
# aaa new-model
# aaa authentication login default local
# aaa session-id common
#
# ip cef
# no ipv6 cef
#
# multilink bundle-name authenticated
#
# interface GigabitEthernet0/0
# ip address 10.1.1.2 255.255.255.252