[netbox.netbox.netbox_device] Collection v3.1.0: More than one result returned for rack #4902

Closed
opened 2025-12-29 19:21:57 +01:00 by adam · 2 comments
Owner

Originally created by @igloo777 on GitHub (May 12, 2021).

NetBox version

v.2.11.2

Python version

3.8

Steps to Reproduce

  1. Create test set:
  • test-site1
    • Rack1
    • Rack999
  • test-site2
    • Rack1
  • test-switch1
---
- hosts: localhost
  collections: netbox.netbox
  vars:
    netbox_url: "https://localhost"
    netbox_token: "token"
  
  tasks:
    - name: Update Site1
      netbox.netbox.netbox_site:
        netbox_url: "{{ netbox_url }}"
        netbox_token: "{{ netbox_token }}"
        data:
          name: test-site1
          status: Active
        state: present
        validate_certs: false

    - name: Test Site1 - Rack1
      netbox.netbox.netbox_rack:
        netbox_url: "{{ netbox_url }}"
        netbox_token: "{{ netbox_token }}"
        data:
          name: Rack1
          site: test-site1
          status: Active
          type: Wall-mounted cabinet
          u_height: 12
        state: present
        validate_certs: false

    - name: Test Site1 - Rack999
      netbox.netbox.netbox_rack:
        netbox_url: "{{ netbox_url }}"
        netbox_token: "{{ netbox_token }}"
        data:
          name: Rack999
          site: test-site1
          status: Active
          type: Wall-mounted cabinet
          u_height: 12
        state: present
        validate_certs: false

    - name: Update Site2
      netbox.netbox.netbox_site:
        netbox_url: "{{ netbox_url }}"
        netbox_token: "{{ netbox_token }}"
        data:
          name: test-site2
          status: Active
        state: present
        validate_certs: false

    - name: Test Site2 - Rack1
      netbox.netbox.netbox_rack:
        netbox_url: "{{ netbox_url }}"
        netbox_token: "{{ netbox_token }}"
        data:
          name: Rack1
          site: test-site2
          status: Active
          type: Wall-mounted cabinet
          u_height: 12
        state: present
        validate_certs: false

    - name: Configure test switch test1
      netbox.netbox.netbox_device:
        netbox_url: "{{ netbox_url }}"
        netbox_token: "{{ netbox_token }}"
        data:
          name: test-switch1
          device_type: PowerSwitch N1548P
          device_role: Access Switch
          platform: Dell OS6
          site: test-site1
          rack: Rack1
          status: planned
        state: present
        validate_certs: false
  1. Attach test-switch1 to test-site1/Rack1 to get error

If I attach test-switch1 to test-site1/Rack999 (uniq rack) i get no error.

It seems like the "site" attribute is not included in the search query.

Expected Behavior

I expect the query should return only one result.

Observed Behavior

The full traceback is:
  File "/tmp/ansible_netbox.netbox.netbox_device_payload_4v8rx3m5/ansible_netbox.netbox.netbox_device_payload.zip/ansible_collections/netbox/netbox/plugins/module_utils/netbox_utils.py", line 559, in _nb_endpoint_get
    response = nb_endpoint.get(**query_params)
  File "/home/igloo/.local/lib/python3.8/site-packages/pynetbox/core/endpoint.py", line 141, in get
    raise ValueError(
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "data": {
                "asset_tag": null,
                "cluster": null,
                "comments": null,
                "custom_fields": null,
                "device_role": "Access Switch",
                "device_type": "PowerSwitch N1548P",
                "face": null,
                "local_context_data": null,
                "name": "test-switch1",
                "platform": "Dell OS6",
                "position": null,
                "primary_ip4": null,
                "primary_ip6": null,
                "rack": "Rack1",
                "serial": null,
                "site": "test-site1",
                "status": "planned",
                "tags": null,
                "tenant": null,
                "vc_position": null,
                "vc_priority": null,
                "virtual_chassis": null
            },
            "netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "netbox_url": "https://test.lcl",
            "query_params": null,
            "state": "present",
            "validate_certs": false
        }
    }
}

MSG:

More than one result returned for rack
Originally created by @igloo777 on GitHub (May 12, 2021). ### NetBox version v.2.11.2 ### Python version 3.8 ### Steps to Reproduce 1. Create test set: - test-site1 - Rack1 - Rack999 - test-site2 - Rack1 - test-switch1 ```yaml --- - hosts: localhost collections: netbox.netbox vars: netbox_url: "https://localhost" netbox_token: "token" tasks: - name: Update Site1 netbox.netbox.netbox_site: netbox_url: "{{ netbox_url }}" netbox_token: "{{ netbox_token }}" data: name: test-site1 status: Active state: present validate_certs: false - name: Test Site1 - Rack1 netbox.netbox.netbox_rack: netbox_url: "{{ netbox_url }}" netbox_token: "{{ netbox_token }}" data: name: Rack1 site: test-site1 status: Active type: Wall-mounted cabinet u_height: 12 state: present validate_certs: false - name: Test Site1 - Rack999 netbox.netbox.netbox_rack: netbox_url: "{{ netbox_url }}" netbox_token: "{{ netbox_token }}" data: name: Rack999 site: test-site1 status: Active type: Wall-mounted cabinet u_height: 12 state: present validate_certs: false - name: Update Site2 netbox.netbox.netbox_site: netbox_url: "{{ netbox_url }}" netbox_token: "{{ netbox_token }}" data: name: test-site2 status: Active state: present validate_certs: false - name: Test Site2 - Rack1 netbox.netbox.netbox_rack: netbox_url: "{{ netbox_url }}" netbox_token: "{{ netbox_token }}" data: name: Rack1 site: test-site2 status: Active type: Wall-mounted cabinet u_height: 12 state: present validate_certs: false - name: Configure test switch test1 netbox.netbox.netbox_device: netbox_url: "{{ netbox_url }}" netbox_token: "{{ netbox_token }}" data: name: test-switch1 device_type: PowerSwitch N1548P device_role: Access Switch platform: Dell OS6 site: test-site1 rack: Rack1 status: planned state: present validate_certs: false ``` 2. Attach test-switch1 to test-site1/Rack1 to get error If I attach test-switch1 to test-site1/Rack999 (uniq rack) i get no error. It seems like the "site" attribute is not included in the search query. ### Expected Behavior I expect the query should return only one result. ### Observed Behavior ``` The full traceback is: File "/tmp/ansible_netbox.netbox.netbox_device_payload_4v8rx3m5/ansible_netbox.netbox.netbox_device_payload.zip/ansible_collections/netbox/netbox/plugins/module_utils/netbox_utils.py", line 559, in _nb_endpoint_get response = nb_endpoint.get(**query_params) File "/home/igloo/.local/lib/python3.8/site-packages/pynetbox/core/endpoint.py", line 141, in get raise ValueError( fatal: [localhost]: FAILED! => { "changed": false, "invocation": { "module_args": { "data": { "asset_tag": null, "cluster": null, "comments": null, "custom_fields": null, "device_role": "Access Switch", "device_type": "PowerSwitch N1548P", "face": null, "local_context_data": null, "name": "test-switch1", "platform": "Dell OS6", "position": null, "primary_ip4": null, "primary_ip6": null, "rack": "Rack1", "serial": null, "site": "test-site1", "status": "planned", "tags": null, "tenant": null, "vc_position": null, "vc_priority": null, "virtual_chassis": null }, "netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "netbox_url": "https://test.lcl", "query_params": null, "state": "present", "validate_certs": false } } } MSG: More than one result returned for rack ```
adam added the type: bug label 2025-12-29 19:21:57 +01:00
adam closed this issue 2025-12-29 19:21:57 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 12, 2021):

I think maybe you want the ansible_modules project.

@jeremystretch commented on GitHub (May 12, 2021): I think maybe you want the [ansible_modules project](https://github.com/netbox-community/ansible_modules).
Author
Owner

@igloo777 commented on GitHub (May 12, 2021):

I'm sorry, wrong project.

@igloo777 commented on GitHub (May 12, 2021): I'm sorry, wrong project.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4902