netbox-community / ansible_modules

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

[Bug]: Floors with the same name in different sites is not allowed #1233

Closed sapergus closed 1 month ago

sapergus commented 1 month ago

Ansible NetBox Collection version

v.3.18.0

Ansible version

ansible [core 2.16.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/pergus/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/pergus/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True

NetBox version

v3.7.3

Python version

3.10

Steps to Reproduce

If a site already exists in NetBox with a building and a floor and we then try to add another site with the same name for the building and the floor fails.

It does work if I change the line "parent_location": set(["slug"]), to "parent_location": set("name", "slug", "site"]) on line 501 in plugins/module_utils/netbox_utils.py and then make the parent_location into a dictionary as shown below.

locations__configured_locations:

Expected Behavior

I expect that different buildings on different sites should be able to have floors with the same name.

Observed Behavior

failed: [localhost] (item={'name': 'Floor 36', 'site': 'demo', 'parent_location': 'Building Y'}) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "Floor 36", "parent_location": "Building Y", "site": "demo"}, "msg": "More than one result returned for parent_location"}