nautobot/nautobot-lab

Unable to install nautobot_netbox_importer plugin

Kani999 opened this issue · 4 comments

Hello, I'm trying to install nautobot_netbox_importer but, I'm not able to build image with plugin configured.

Environment

  • Python version: 3.8.5
  • Nautobot version: Nautobot-Lab 1.0.0b4
  • nautobot-netbox-importer version: Version 1.2.1

Expected Behavior

Nautobot-lab image built with nautobot_netbox_importer plugin

What happened instead?

Unable to find plugin nautobot_netbox_importer

#17 61.21 TASK [RUN MAKEMIGRATIONS] ******************************************************
#17 61.57 fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["/opt/nautobot/bin/nautobot-server", "makemigrations"], 
"delta": "0:00:00.184857", "end": "2021-04-22 07:25:17.981318", "msg": "non-zero return code", "rc": 1, "start": "2021-04-22 
07:25:17.796461", "stderr": "Traceback (most recent call last):\n  File \"/opt/nautobot/lib/python3.8/site-
packages/nautobot/extras/plugins/utils.py\", line 63, in load_plugin\n    plugin = importlib.import_module(plugin_name)\n  File
 \"/usr/lib/python3.8/importlib/__init__.py\", line 127, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n  File \"<frozen importlib._bootstrap>\", line 1014, in _gcd_import\n  File \"<frozen importlib._bootstrap>\", line 991, in 
_find_and_load\n  File \"<frozen importlib._bootstrap>\", line 973, in _find_and_load_unlocked\nModuleNotFoundError: No 
module named 'nautobot_netbox_importer'\n\nThe above exception was the direct cause of the following 
exception:\n\nTraceback (most recent call last):\n  File \"/opt/nautobot/lib/python3.8/site-
packages/nautobot/core/runner/runner.py\", line 118, in settings_callback\n    initializer(\n  File 
\"/opt/nautobot/lib/python3.8/site-packages/nautobot/core/cli.py\", line 178, in _configure_settings\n    load_plugins(settings)\n  File \"/opt/nautobot/lib/python3.8/site-packages/nautobot/extras/plugins/utils.py\", line 53, in load_plugins\n   
 load_plugin(plugin_name, settings)\n  File \"/opt/nautobot/lib/python3.8/site-packages/nautobot/extras/plugins/utils.py\", line 66, in load_plugin\n    raise PluginNotFound(\nnautobot.extras.plugins.exceptions.PluginNotFound: Unable to import plugin 
nautobot_netbox_importer: Module not found. Check that the plugin module has been installed within the correct Python 
environment.", "stderr_lines": ["Traceback (most recent call last):", "  File \"/opt/nautobot/lib/python3.8/site-
packages/nautobot/extras/plugins/utils.py\", line 63, in load_plugin", "    plugin = importlib.import_module(plugin_name)", "  File \"/usr/lib/python3.8/importlib/__init__.py\", line 127, in import_module", "    return _bootstrap._gcd_import(name[level:], package, level)", "  File \"<frozen importlib._bootstrap>\", line 1014, in _gcd_import", "  File \"<frozen importlib._bootstrap>\", line 991
, in _find_and_load", "  File \"<frozen importlib._bootstrap>\", line 973, in _find_and_load_unlocked", "ModuleNotFoundError: No module named 'nautobot_netbox_importer'", "", "The above exception was the direct cause of the following exception:", "", 
"Traceback (most recent call last):", "  File \"/opt/nautobot/lib/python3.8/site-packages/nautobot/core/runner/runner.py\", line
118, in settings_callback", "    initializer(", "  File \"/opt/nautobot/lib/python3.8/site-packages/nautobot/core/cli.py\", line 178, i
n _configure_settings", "    load_plugins(settings)", "  File \"/opt/nautobot/lib/python3.8/site-
packages/nautobot/extras/plugins/utils.py\", line 53, in load_plugins", "    load_plugin(plugin_name, settings)", "  File 
\"/opt/nautobot/lib/python3.8/site-packages/nautobot/extras/plugins/utils.py\", line 66, in load_plugin", "    raise 
PluginNotFound(", "nautobot.extras.plugins.exceptions.PluginNotFound: Unable to import plugin nautobot_netbox_importer:
 Module not found. Check that the plugin module has been installed within the correct Python environment."], "stdout": "", 
"stdout_lines": []}
PluginNotFound(", "nautobot.extras.plugins.exceptions.PluginNotFound: 
Unable to import plugin nautobot_netbox_importer: Module not found. 
Check that the plugin module has been installed within the correct Python environment."], "stdout": "", "stdout_lines": []}

Steps to Reproduce

  1. Edit templates/requirements.txt
    • Add line nautobot-netbox-importer
  2. Edit templates/nautobot_config.py
    • Edit variable PLUGINS = ["nautobot_netbox_importer"]
  3. Edit Dockerfile
    • trying to install nautobot-netbox-importer extra RUN pip3 install nautobot-netbox-importer
  4. Build nautobot-lab image
    • docker build -t nautobot-lab:latest .
      • Error occurs

Am I missing some other configuration?

I think with the approach you’re using the plugin is getting installed to the global Python library, rather than the Nautobot virtualenv. Instead of your steps 1 and 3, try adding the following to pb_nautobot_install.yml between the INSTALL NAUTOBOT and RUN NAUTOBOT-SERVER INIT steps:

- name: "INSTALL PLUGIN"
  ansible.builtin.pip:
    name: "nautobot-netbox-importer==1.2.1"
    virtualenv: "{{ nautobot_root }}"
    virtualenv_command: "python3 -m venv"
jtdub commented

Hi @Kani999, @glennmatthews's approach should work perfectly. Let us know if that doesn't work for you.

(If we don't already have plans to add some documentation on how to do exactly this, I'd recommend it. :-) )

Everything works fine now.
Thank you.