-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vxlan
37 lines (27 loc) · 1.08 KB
/
.vxlan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Python script to configure VLXAN nodes from templates"""
import logging
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from nornir_scrapli.tasks import send_configs
from nornir_jinja2.plugins.tasks import template_file
from nornir_utils.plugins.tasks.data import load_yaml
nr = InitNornir(config_file="config.yaml")
def load_vars(task):
loader = task.run(task=load_yaml, file=f"host_vars/{task.host}.yaml")
group_loader = task.run(task=load_yaml, file="group_vars/all.yaml")
task.host["facts"] = loader.result
task.host["group_facts"] = group_loader.result
def vxlan_configs(task):
template = task.run(
task=template_file,
template=f"{task.host['layer']}.j2",
path="templates/vxlan",
severity_level=logging.DEBUG,
)
task.host["vxlan_config"] = template.result
rendered = task.host["vxlan_config"]
configuration = rendered.splitlines()
task.run(task=send_configs, configs=configuration)
nr.run(task=load_vars)
vxlan_results = nr.run(task=vxlan_configs)
print_result(vxlan_results)