Accessing data items in inventory


I have the following Jinja2 template that I can not make it work deseperatly :

{% for vlan in host.vlans %}
vlan {{ }}
name {{ }}
{% endfor %}

And the following python code:

from nornir import InitNornir
from nornir.plugins.tasks import networking, text
from nornir.plugins.functions.text import print_title, print_result
from tqdm import tqdm

def service_L2(task):
# Transform inventory data to configuration via a template file
r =,
name=“Generate L2 services configuration for devices”,

# Save the compiled configuration into a host variable["config"] = r.result

# Deploy that configuration to the device using NAPALM,
         name="Loading L2 services configuration on devices",

nr = InitNornir(config_file=“config.yml”, dry_run=False)
ACH_leaf = nr.filter(site=“ACH”, type=“network_device”, role=“leaf”)

result1 =

But I’ve got this error when parsing the jinja2 template :

> File “templates/eos/service_L2.j2”, line 6, in top-level template code
> {% for vlan in host.vlans %}
> jinja2.exceptions.UndefinedError: ‘nornir.core.inventory.Host object’ has no attribute ‘vlans’
> ^^^^ END service_L2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Thank you for your help !

Finally, I found the error. The filters I used pointed to other devices in the inventory file without the required keywords.