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

Problem updating locations which have a parent_location #303

Closed
nicholaskuechler opened this issue Jan 11, 2024 · 0 comments · Fixed by #304
Closed

Problem updating locations which have a parent_location #303

nicholaskuechler opened this issue Jan 11, 2024 · 0 comments · Fixed by #304

Comments

@nicholaskuechler
Copy link
Contributor

ISSUE TYPE
  • Bug Report
SOFTWARE VERSIONS
pynautobot
pynautobot==2.0.1
Ansible:
ansible==8.5.0
ansible-core==2.15.5
Nautobot:

2.0.6

Collection:
networktocode.nautobot        5.1.0
SUMMARY

I'm unable to add/update locations when using parent_location due to the 'icontains' search finding multiple locations.

I found a similar, possibly related issue: #199

STEPS TO REPRODUCE

Here's a snippet of my ansible vars and task:

# Create a "Global" location which has no parent and will be
# the parent for all other locations.
# Note: there's no 'parent_location' in this block
- name: Create Global location
  networktocode.nautobot.location:
    url: "{{ nautobot_url }}"
    token: "{{ nautobot_token }}"
    name: "Global"
    description: "Global"
    location_type: "Global"
    status: "Active"
    state: present

- name: Create default locations
  networktocode.nautobot.location:
    url: "{{ nautobot_url }}"
    token: "{{ nautobot_token }}"
    name: "{{ item.name }}"
    description: "{{ item.description }}"
    parent_location: "{{ item.parent_location }}"
    location_type: "{{ item.location_type }}"
    status: "{{ item.status }}"
    state: present
  loop: "{{ locations_defaults }}"
locations_defaults:
  - name: Company
    description: Company
    parent_location: Global
    location_type: Company
    status: Active
  - name: ABC
    description: ABC Metro
    parent_location: Company
    location_type: Region
    status: Active
  - name: XYZ
    description: XYZ Metro
    parent_location: Company
    location_type: Region
    status: Active
  - name: ABC1
    description: ABC1 Data Center
    parent_location: ABC
    location_type: Site
    status: Active
  - name: XYZ1
    description: XYZ1 Data Center
    parent_location: XYZ
    location_type: Site
    status: Active

The above works if I do not already have any locations created.

But if I run the ansible a second time, I get an error indicating nautobot has found duplicate entries:

TASK [locations : Create default locations] ********************************************************************************************************************************************************************
changed: [0.0.0.0] => (item={'name': 'Company', 'description': 'Company', 'parent_location': 'Global', 'location_type': 'Company', 'status': 'Active'})
changed: [0.0.0.0] => (item={'name': 'ABC', 'description': 'ABC Metro', 'parent_location': 'Company', 'location_type': 'Region', 'status': 'Active'})
changed: [0.0.0.0] => (item={'name': 'XYZ', 'description': 'XYZ Metro', 'parent_location': 'Company', 'location_type': 'Region', 'status': 'Active'})
failed: [0.0.0.0] (item={'name': 'ABC1', 'description': 'ABC1 Data Center', 'parent_location': 'ABC', 'location_type': 'Site', 'status': 'Active'}) => changed=false
  ansible_loop_var: item
  item:
    description: ABC1 Data Center
    location_type: Site
    name: ABC1
    parent_location: ABC
    status: Active
  msg: More than one result returned for parent_location
failed: [0.0.0.0] (item={'name': 'XYZ1', 'description': 'XYZ1 Data Center', 'parent_location': 'XYZ', 'location_type': 'Site', 'status': 'Active'}) => changed=false
  ansible_loop_var: item
  item:
    description: XYZ1 Data Center
    location_type: Site
    name: XYZ1
    parent_location: XYZ
    status: Active
  msg: More than one result returned for parent_location
EXPECTED RESULTS

Location added/updated without error when using a parent_location.

ACTUAL RESULTS
  msg: More than one result returned for parent_location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant