0
from nornir import InitNornir
from nornir_napalm.plugins.tasks import napalm_get
from nornir_utils.plugins.functions import print_result
import json

def prettyPrintDictionary(dict):
  print(json.dumps(dict, indent=2))


nr = InitNornir(config_file="/home/python/nornir-scripts/config.yaml")

print(nr.inventory.hosts)


prettyPrintDictionary(nr.inventory.get_hosts_dict())
# config.yaml
inventory:
  plugin: SimpleInventory
  options:
    host_file: '/home/python/nornir-scripts/inventory/hosts.yaml'
    group_file: '/home/python/nornir-scripts/inventory/groups.yaml'
    defaults_file: '/home/python/nornir-scripts/inventory/defaults.yaml'
runner:
   plugin: threaded
   options:
     num_workers: 100

请帮助我无法理解如何初始化 nornir 我尝试用指南来做它也有错误。现在我有这个错误......

4

1 回答 1

0

根据文档num_workers钥匙应该在runner.options钥匙里面。将其添加到options密钥并重试:

inventory:
  plugin: nornir.plugins.inventory.simple.SimpleInventory
  options:
    host_file: 'inventory/hosts.yaml'
    group_file: 'inventory/groups.yaml'
    defaults_file: 'inventory/defaults.yaml'
runner:
   plugin: threaded
   options:
     num_workers: 100
于 2020-12-14T14:19:55.517 回答