What is wrong with this code example?

I’ve been working with the following code from this blog post on DevNet. I’m getting my feet wet with Nornir, but I’m finding out that this code is not correct and doesn’t appear to load variables into the Jinja2 script.

I’m running the exact same code, and I get this error:

oad_data***********************************************************************
* R4 ** changed : False ********************************************************
vvvv load_data ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ERROR
Subtask: <function template_file at 0x7f9dccd57f28> (failed)

---- load_yaml ** changed : False ---------------------------------------------- INFO
{ 'asn': 64879,
  'networks': [ {'mask': '255.255.255.0', 'net': '10.91.53.0'},
                {'mask': '255.255.255.0', 'net': '10.91.54.0'},
                {'mask': '255.255.255.0', 'net': '10.91.55.0'},
                {'mask': '255.255.255.0', 'net': '10.91.56.0'},
                {'mask': '255.255.255.0', 'net': '10.91.57.0'},
                {'mask': '255.255.255.0', 'net': '10.91.58.0'}]}
---- template_file ** changed : False ------------------------------------------ ERROR
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/nornir/core/task.py", line 85, in start
    r = self.task(self, **self.params)
  File "/usr/local/lib/python3.6/site-packages/nornir/plugins/tasks/text/template_file.py", line 35, in template_file
    **kwargs
  File "/usr/local/lib/python3.6/site-packages/nornir/core/helpers/jinja_helper.py", line 18, in render_from_file
    return t.render(**kwargs)
  File "/usr/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "bgp-template.j2", line 1, in top-level template code
    router bgp {{ asn }}
jinja2.exceptions.UndefinedError: 'asn' is undefined

^^^^ END load_data ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

My code is this:
from nornir import InitNornir
from nornir.plugins.tasks.data import load_yaml
from nornir.plugins.tasks.text import template_file
from nornir.plugins.functions.text import print_result

def load_data(task):
    data = task.run(
           task=load_yaml,
           file=f'{task.host["site"]}.yaml'
    )

    task.host["asn"] = data.result["asn"]
    task.host["networks"] = data.result["networks"]
    task.host["template_config"] = task.run(task=template_file,
                                            template="router.j2", path=""
                                            asn = asn, networks = networks)


nr = InitNornir()
routers = nr.filter(site="Site4")
r = routers.run(load_data)
print_result(r)

Any ideas?

No coma after “path=”"" ?