nornir-automation / nornir

Pluggable multi-threaded framework with inventory management to help operate collections of devices
https://nornir.readthedocs.io/
Apache License 2.0
1.38k stars 234 forks source link

NTC-Templates custom directory #789

Closed resparis closed 2 years ago

resparis commented 2 years ago

Hi All,

I want to use a custom dictory for NTC-Templaces with Netmiko.

So far I tried: from nornir import InitNornir from nornir_netmiko.tasks import netmiko_send_command, netmiko_send_config from nornir_utils.plugins.functions import print_result import json import os

os.environ["NTC_TEMPLATES_DIR"] = "/ntc_templates/" result = nr.run(netmiko_send_command, command_string="show vpls mac-table instance", use_textfsm=True)

But it is not working.

Any ideas?

ktbyers commented 2 years ago

@resparis This isn't a Nornir issue (so issue should either be in Netmiko or Nornir-Netmiko repository and not in main Nornir repository).

So you have your own index file? What is the full path to the index file?

resparis commented 2 years ago

@ktbyers thanks for the quick response. The full path is /home/resparis/Documents/Health_Check/ntc_templates/

I just tried os.environ["NTC_TEMPLATES_DIR"] = "/home/resparis/Documents/Health_Check/ntc_templates/" and did not work either.

(hc_env) resparis@ubuntu:~/Documents/Health_Check/ntc_templates$ pwd /home/resparis/Documents/Health_Check/ntc_templates (hc_env) resparis@ubuntu:~/Documents/Health_Check/ntc_templates$ ls -la total 56 drwxrwxr-x 2 resparis resparis 4096 Mar 17 05:42 . drwxrwxr-x 6 resparis resparis 4096 Mar 17 09:01 .. -rw-rw-r-- 1 resparis resparis 41393 Mar 17 05:43 index -rw-rw-r-- 1 resparis resparis 148 Mar 17 05:32 juniper_junos_show_vpls_mac_table_instance2.textfsm (hc_env) resparis@ubuntu:~/Documents/Health_Check/ntc_templates$ more index | grep vpls juniper_junos_show_vpls_mac_table_instance2.textfsm, .*, juniper_junos, show vpls mac-table instance

ktbyers commented 2 years ago

I don't see a TextFSM index file there?

If you just have a specific template file you want to use, then you need to use the following two arguments:

use_textfsm=True
textfsm_template="/path/to/textfsm_file.tpl
ktbyers commented 2 years ago

You would use these as arguments here:

result = nr.run(netmiko_send_command, command_string="show vpls mac-table instance", use_textfsm=True)

resparis commented 2 years ago

I don't see a TextFSM index file there?

If you just have a specific template file you want to use, then you need to use the following two arguments:

use_textfsm=True
textfsm_template="/path/to/textfsm_file.tpl

It is there:

(hc_env) resparis@ubuntu:~/Documents/Health_Check/ntc_templates$ ls -la total 56 drwxrwxr-x 2 resparis resparis 4096 Mar 17 05:42 . drwxrwxr-x 6 resparis resparis 4096 Mar 17 09:01 .. -rw-rw-r-- 1 resparis resparis 41393 Mar 17 05:43 index -rw-rw-r-- 1 resparis resparis 148 Mar 17 05:32 juniper_junos_show_vpls_mac_table_instance2.textfsm

ktbyers commented 2 years ago

Did you edit the index file and add your entry?

It might be easier just to point directly at the template file (as per the commands I sent above).

dbarrosop commented 2 years ago

Feel free to keep discussing here if you want but I am closing the issue as this is not a problem with nornir itself

resparis commented 2 years ago

textfsm_template

I just test adding template path as you suggested. It worked. Thanks a lot