netbox-community / ansible_modules

NetBox modules for Ansible using Ansible Collections
GNU General Public License v3.0
333 stars 216 forks source link

[Bug]: Multiple results returned when assigning device to rack whose name is only unique to location #1123

Open stanier opened 11 months ago

stanier commented 11 months ago

Ansible NetBox Collection version

v3.8.0

Ansible version

ansible [core 2.13.5]
  config file = /home/keyton/git/gacrc_git/sysadmin/gacrc-ansible-projects/playbooks/gacrc-provisioning-playbook/ansible.cfg
  configured module search path = ['/home/keyton/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/keyton/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/keyton/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/keyton/.local/bin/ansible
  python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
  jinja version = 3.1.2
  libyaml = True

NetBox version

v3.5.4

Python version

3.10

Steps to Reproduce

DCIM Staging:

Ansible task:

---
- name: Update rack of compute nodes
  netbox_device:
    netbox_url: "{{ netbox_url }}"
    netbox_token: "{{ netbox_token }}"
    validate_certs: "{{ netbox_ssl_toggle }}"
    data:
      name: "foobar"
      rack: "A-1"
      location: "ACME"
      status: Planned
    state: present

Expected Behavior

The device is assigned to the rack object corresponding to the name and location specified in the device configuration (data): device "foobar" is placed into rack "A-1" of location "ACME"

If multiple racks with the same name are encountered, only the racks that are in the specified location should be returned.

Ex:

Observed Behavior

All racks matching the specified rack name across all locations are returned, causing a "More than one result returned for rack" error to be thrown: the task does not update the device's rack because it sees multiple racks named "A-1" across multiple locations

All racks matching the rack name are returned when we should only be getting one whose name matches and is a member of the specified location.

vishnubraj commented 6 months ago

Please check this https://github.com/netbox-community/ansible_modules/issues/515