Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'pynetbox' #289

Open
igorjip opened this issue Feb 6, 2025 · 1 comment
Open

ModuleNotFoundError: No module named 'pynetbox' #289

igorjip opened this issue Feb 6, 2025 · 1 comment

Comments

@igorjip
Copy link

igorjip commented Feb 6, 2025

Hello!
I'm trying to do query to Netbox from Ansible.
But I received error :
"msg": "An unhandled exception occurred while running the lookup plugin 'netbox.netbox.nb_lookup'. Error was a <class 'ansible.errors.AnsibleError'>, original message: pynetbox must be installed to use this plugin. pynetbox must be installed to use this plugin"
and when I saw debug, I saw
"import pynetbox
ModuleNotFoundError: No module named 'pynetbox".
Pynetbox installed
ansible-01:~/myenv00$ pip list
Package Version


certifi 2025.1.31
charset-normalizer 3.4.1
idna 3.10
packaging 24.2
pip 23.0.1
pynetbox 7.4.1
requests 2.32.3
setuptools 66.1.1
urllib3 2.3.0


My yml-file

  • name: "Test NetBox modules"
    connection: local
    hosts: localhost
    gather_facts: false

    vars:
    ansible_python_interpreter: bin/python3
    tasks:

    • name: Obtain list of devices from NetBox
      debug:
      msg: "Device {{ item.value.display_name }} (ID: {{ item.key }}) was manufactured by {{ item.value.device_type.manufacturer.name }}"
      loop: "{{ query( 'netbox.netbox.nb_lookup','devices', api_endpoint='http://10.1.50.3', token='11111111111111111111') }}"

my debug


ansible-01:~/myenv00$ ansible-playbook pb_create_device_w_primary_ip.yml -vvvvvvv
ansible-playbook [core 2.14.18]
config file = /home/test/myenv00/ansible.cfg
configured module search path = ['/home/test/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/test/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible-playbook
python version = 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
Using /home/test/myenv00/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3/dist-packages/ansible/plugins/callback/default.py
Attempting to use 'default' callback.
Skipping callback 'default', as we already have a stdout callback.
Attempting to use 'junit' callback.
Attempting to use 'minimal' callback.
Skipping callback 'minimal', as we already have a stdout callback.
Attempting to use 'oneline' callback.
Skipping callback 'oneline', as we already have a stdout callback.
Attempting to use 'tree' callback.

PLAYBOOK: pb_create_device_w_primary_ip.yml ******************************************************************************************************************************************
Positional arguments: pb_create_device_w_primary_ip.yml
verbosity: 7
remote_user: test
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
forks: 5
1 plays in pb_create_device_w_primary_ip.yml

PLAY [Test NetBox modules] ***********************************************************************************************************************************************************

TASK [Obtain list of devices from NetBox] ********************************************************************************************************************************************
task path: /home/test/myenv00/pb_create_device_w_primary_ip.yml:15
Loading collection netbox.netbox from /home/test/.ansible/collections/ansible_collections/netbox/netbox
[WARNING]: Collection netbox.netbox does not support Ansible version 2.14.18
exception during Jinja2 execution: Traceback (most recent call last):
File "/home/test/.ansible/collections/ansible_collections/netbox/netbox/plugins/lookup/nb_lookup.py", line 121, in
import pynetbox
ModuleNotFoundError: No module named 'pynetbox'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/ansible/template/init.py", line 816, in _lookup
ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/test/.ansible/collections/ansible_collections/netbox/netbox/plugins/lookup/nb_lookup.py", line 393, in run
raise_from(
File "", line 3, in raise_from
ansible.errors.AnsibleError: pynetbox must be installed to use this plugin
fatal: [localhost]: FAILED! => {
"msg": "An unhandled exception occurred while running the lookup plugin 'netbox.netbox.nb_lookup'. Error was a <class 'ansible.errors.AnsibleError'>, original message: pynetbox must be installed to use this plugin. pynetbox must be installed to use this plugin"

Help me please.
Have any idea?

@mjbear
Copy link
Contributor

mjbear commented Feb 6, 2025

@igorjip
The formatting is tougher to follow when not in code fences

Are you using pip globally or with a Python virtual environment?

If you're using a Python virtual environment, did you activate it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants