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

AttributeError: 'dict' object has no attribute 'split' #688

Closed rg0809 closed 3 years ago

rg0809 commented 3 years ago

while executing below code

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

nr = InitNornir(
    config_file="config.yaml", dry_run=True
)

results = nr.run(
    task=napalm_get, getters=["facts", "interfaces"]
)
print_result(results)

getting error

/Users/ral/PycharmProjects/NWScripting/venv/lib/python3.9/site-packages/nornir/core/configuration.py:96: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  data = yaml.load(f.read()) or {}
Traceback (most recent call last):
  File "/Users/ral/PycharmProjects/NWScripting/06_Nornir_Python/test.py", line 5, in <module>
    nr = InitNornir(
  File "/Users/ral/PycharmProjects/NWScripting/venv/lib/python3.9/site-packages/nornir/core/__init__.py", line 261, in InitNornir
    conf = Config(config_file=config_file, **kwargs)
  File "/Users/ral/PycharmProjects/NWScripting/venv/lib/python3.9/site-packages/nornir/core/configuration.py", line 112, in __init__
    obj = self._resolve_import_from_string(kwargs.get(r, getattr(self, r)))
  File "/Users/ral/PycharmProjects/NWScripting/venv/lib/python3.9/site-packages/nornir/core/configuration.py", line 177, in _resolve_import_from_string
    module_name = ".".join(import_path.split(".")[:-1])
AttributeError: 'dict' object has no attribute 'split'
ubaumann commented 3 years ago

Looks like your config.yaml is not correct. Instead of a string to describe a module you have a mapping

rg0809 commented 3 years ago

this is content of config.yaml file

---
inventory:
     plugin: SimpleInventory
     options:
         host_file: '00_host.yaml'
         group_file: '00_groups.yaml'
         defaults_file: '00_defaults.yaml'
runner:
     plugin: threaded
     options:
         num_workers: 100
dbarrosop commented 3 years ago

I suspect there is something wrong with your environment. That exception you are getting suggest you are running nornir 2 with a configuration file for nornir 3.

dbarrosop commented 3 years ago

I am closing the issue as I am 90% certain that's the case but feel free to reopen otherwise.

Thanks!