-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
57 lines (47 loc) · 1.49 KB
/
config.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import logging
from nornir_netmiko.tasks import netmiko_send_config
from nornir_utils.plugins.functions import print_result
from nornir_utils.plugins.tasks.data import load_yaml
from nornir_jinja2.plugins.tasks import template_file
from nornir import InitNornir
from nornir.core.filter import F
nr = InitNornir()
def load_vars(task):
data = task.run(task=load_yaml, file=f"./host_vars/{task.host}.yaml")
task.host["facts"] = data.result
def push_isis(task):
result = task.run(
task=template_file,
template="isis.j2",
path="./templates",
severity_level=logging.DEBUG,
)
task.host["isis_config"] = result.result
isis_output = task.host["isis_config"]
isis_send = isis_output.splitlines()
task.run(
task=netmiko_send_config,
name="Pushing ISIS Commands",
config_commands=isis_send,
)
def push_vxlan(task):
result = task.run(
task=template_file,
template="vxlan.j2",
path="./templates",
severity_level=logging.DEBUG,
)
task.host["vxlan_config"] = result.result
vxlan_output = task.host["vxlan_config"]
vxlan_send = vxlan_output.splitlines()
task.run(
task=netmiko_send_config,
name="Pushing VXLAN Commands",
config_commands=vxlan_send,
)
pull_vars = nr.run(task=load_vars)
routing = nr.run(task=push_isis)
vxlan_targets = nr.filter(F(groups__contains="leafs"))
vxlan = vxlan_targets.run(task=push_vxlan)
print_result(routing)
print_result(vxlan)