You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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
The text was updated successfully, but these errors were encountered:
ISSUE TYPE
SOFTWARE VERSIONS
pynautobot
Ansible:
Nautobot:
2.0.6
Collection:
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:
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:
EXPECTED RESULTS
Location added/updated without error when using a parent_location.
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: