ansible_modules icon indicating copy to clipboard operation
ansible_modules copied to clipboard

[Bug]: certain modules fail when parsing new NetBox-Docker version string format

Open riyad opened this issue 1 year ago • 8 comments

Ansible NetBox Collection version

v3.20.0

Ansible version

ansible [core 2.18.1]
  config file = /home/riyad/Projects/ansible-netbox/ansible.cfg
  configured module search path = ['/home/riyad/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/riyad/Projects/ansible-netbox/.venv/lib/python3.12/site-packages/ansible
  ansible collection location = /home/riyad/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/riyad/Projects/ansible-netbox/.venv/bin/ansible
  python version = 3.12.7 (main, Jan 17 2025, 16:55:27) [GCC 14.2.0] (/home/riyad/Projects/ansible-netbox/.venv/bin/python)
  jinja version = 3.1.5
  libyaml = True

NetBox version

4.2.3-Docker-3.2.0 (from https://github.com/netbox-community/netbox-docker)

Python version

3.11

Steps to Reproduce

Run a module that checks the NetBox version against the NetBox-Docker version starting from 3.2.0 . In my case at least the netbox_rack is affected.

Expected Behavior

Should work as before.

Observed Behavior

Running the netbox_rack module against the Docker version of NetBox seems to fails with the following error:

[...]
The full traceback is:
Traceback (most recent call last):
  File "master:/home/riyad/Projects/ansible-netbox/library/mitogen/ansible_mitogen/runner.py", line 1039, in _run
    self._run_code(code, mod)
  File "master:/home/riyad/Projects/ansible-netbox/library/mitogen/ansible_mitogen/runner.py", line 1003, in _run_code
    exec(code, vars(mod))
  File "master:/home/riyad/.ansible/collections/ansible_collections/netbox/netbox/plugins/modules/netbox_rack.py", line 346, in <module>
  File "master:/home/riyad/.ansible/collections/ansible_collections/netbox/netbox/plugins/modules/netbox_rack.py", line 342, in main
  File "master:/home/riyad/.ansible/collections/ansible_collections/netbox/netbox/plugins/module_utils/netbox_dcim.py", line 130, in run
    if Version(self.full_version) >= Version("4.1.0"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/riyad/Projects/ansible-netbox/.venv/lib/python3.12/site-packages/packaging/version.py", line 202, in __init__
    raise InvalidVersion(f"Invalid version: {version!r}")
packaging.version.InvalidVersion: Invalid version: '4.2.3-Docker-3.2.0'
[...]

This started after updating to version 3.2.0 of the NetBox-Docker project where it seems to have started to include its version number in the version string as well (i.e. "4.2.3-Docker-3.2.0").

May be caused by https://github.com/netbox-community/netbox-docker/pull/1380 ?

riyad avatar Feb 08 '25 20:02 riyad

I am getting something similar with netbox.netbox.netbox_virtual_machine and netbox.netbox.netbox_vm_interface modules, python3.12

"msg": "Failed to establish connection to NetBox API"

The full traceback is:
  File "/var/folders/s4/bh0s3kz51g166t27lwwz9zbw0000gp/T/ansible_netbox.netbox.netbox_virtual_machine_payload_oguhsl20/ansible_netbox.netbox.netbox_virtual_machine_payload.zip/ansible_collections/netbox/netbox/plugins/module_utils/netbox_utils.py", line 811, in _connect_netbox_api
    self.version = nb.version
                   ^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/pynetbox/core/api.py", line 113, in version
    ).get_version()
      ^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/pynetbox/core/query.py", line 198, in get_version
    raise RequestError(req)

Jurka007 avatar Feb 12 '25 12:02 Jurka007

Can I suggest you raise this issue with the netbox-docker repository? I find it a bit strange that the netbox-docker image changes the netbox-version in /api/status to indicate it's running a docker image. I would expect the netbox-version to be the actual netbox version running, not that the netbox version is running using docker.

rodvand avatar Feb 12 '25 19:02 rodvand

After investigating this a bit more I've opened an issue in the main NetBox repository: https://github.com/netbox-community/netbox/issues/18635

rodvand avatar Feb 12 '25 20:02 rodvand

Thank you for looking into this. Is there any way we could help?

riyad avatar Feb 13 '25 11:02 riyad

If you're building your own image you can remove the file /opt/netbox/netbox/local/release.yaml in your build to circumvent this issue.

rodvand avatar Mar 04 '25 22:03 rodvand

@rodvand I am using some necromancy to resurrect this issue but what are your thoughts about manipulating the release.yaml file for the docker image we use in our CI/CD tests, to fix this issue in our CI/CD pipeline?

sc68cal avatar Jun 20 '25 17:06 sc68cal

@rodvand I am using some necromancy to resurrect this issue but what are your thoughts about manipulating the release.yaml file for the docker image we use in our CI/CD tests, to fix this issue in our CI/CD pipeline?

Feel free to make any adjustments needed. Not sure how you'll make the adjustment, but it would be nice to get the CI/CD working again.

rodvand avatar Jun 20 '25 17:06 rodvand

I am hoping that perhaps we can discuss with @tobiasge https://github.com/netbox-community/netbox-docker/pull/1386#issuecomment-2649909156 and determine a way forward that works for everyone, perhaps by changing the Dockerfile slightly for 4.1 versions so it reports the version string without the docker information in it, as a sort of "backport"

EDIT: only needed for version 4.1

sc68cal avatar Jun 20 '25 17:06 sc68cal