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
[Bug]: Nebox_location module updates existing locations instead of creating new ones in a different site #958
Comments
Can you provide a log of the playbook run with the verbosity increased ( |
Here you go: "invocation": {
"module_args": {
"netbox_url": "https://netbox",
"netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": "/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt",
"data": {
"name": "Office Data Center",
"description": "Office building",
"parent_location": "Marupe",
"site": "Marupe",
"tenant": "xxx",
"tags": [
"Latvia",
"Marupe"
],
"slug": null,
"custom_fields": null
},
"state": "present",
"query_params": null,
"cert": null
}
},
"_ansible_no_log": false,
"ansible_loop_var": "location",
"_ansible_item_label": "('Marupe', 'Office Data Center')"
}
Not sure how to get the output with -vvv from AWX though. |
OK, don't worry about the |
What are the |
Also while we're at it, what is the |
Yeah, sorry, here are both items in the loop for comparison: "invocation": {
"module_args": {
"netbox_url": "https://netbox",
"netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": "/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt",
"data": {
"name": "Marupe",
"description": "Main location",
"site": "Marupe",
"tenant": "xx",
"tags": [
"Latvia",
"Marupe"
],
"slug": null,
"parent_location": null,
"custom_fields": null
},
"state": "present",
"query_params": null,
"cert": null
}
},
"_ansible_no_log": false,
"ansible_loop_var": "location",
"_ansible_item_label": "('Marupe', 'Marupe')"
} "invocation": {
"module_args": {
"netbox_url": "https://netbox",
"netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": "/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt",
"data": {
"name": "Office Data Center",
"description": "Office building",
"parent_location": "Marupe",
"site": "Marupe",
"tenant": "xxx",
"tags": [
"Latvia",
"Marupe"
],
"slug": null,
"custom_fields": null
},
"state": "present",
"query_params": null,
"cert": null
}
},
"_ansible_no_log": false,
"ansible_loop_var": "location",
"_ansible_item_label": "('Marupe', 'Office Data Center')"
} The Anticipating your question about uniqueness - it doesn't seem to be required to be unique, as I've just manually created another location in a different site with the same |
And when I have more than one location with the same name already in the system I get this: {
"changed": false,
**"msg": "More than one result returned for Office Data Center",**
"invocation": {
"module_args": {
"netbox_url": "https://netbox",
"netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": "/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt",
"data": {
"name": "Office Data Center",
"description": "Office building",
"parent_location": "Marupe",
"site": "Marupe",
"tenant": "xxx",
"tags": [
"Latvia",
"Marupe"
],
"slug": null,
"custom_fields": null
},
"state": "present",
"query_params": null,
"cert": null
} Not sure if this can be mentioned under the same issue, but this problem carries over to the {
"changed": false,
**"msg": "More than one result returned for location",**
"invocation": {
"module_args": {
"netbox_url": "https://netbox",
"netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": "/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt",
"data": {
"name": "Rack 1",
"location": "Office Data Center",
"tenant": "xxx",
"site": "Marupe",
"status": "Active",
"rack_role": "Mixed",
"facility_id": "Rack 1",
"tags": [
"Latvia",
"Marupe",
"Marupe Office DC"
], |
Are you able to run your playbook locally instead of the AWX server, so that you can set |
Right, so I remembered that there is in fact a way to change the verbosity level in the settings of the AWX template (essentially the runbook that you can run manually). I've ran it twice with verbosity 3 (debug) and 4 (connection debug). Since I already started to populate things in existing locations, I've created a different test site/location pair not to mess with the ones I actually need to keep. The one I currently have is:
What I'm trying to create is: - name: Test Data Center
description: Office building
site: Castle Sky Just to be clear, the result is the same as before - Castle Back is changed to Castle Sky without creating a new object. And here are both outputs (although it doesn't seem like there's much difference between them): |
Great. I'll dig into the logs next week and attempt to replicate the issue locally. Thanks so much for your patience and the information gathering. |
Currently our code only does a lookup based on the slug.
This means we assume the slug to be unique. In this case it's not. The API call being done is something like this: The fix is pretty simple, we add site as a filter so it will be |
Thanks for the quick actions, but I still have a few questions:
Thanks again! |
You should create a separate issue for the netbox_rack issue. If you want to test you can install the collection from a git repository. See https://docs.ansible.com/ansible/latest/collections_guide/collections_installing.html I think the earliest I can craft a new release will be Monday. |
So what's the resulting set of properties for this module then? - name: Office Data Center
description: Office building
parent_location: Marupe
site: "{{ latvia_defaults.site }}"
location:
name: Office Data Center
site: "{{ latvia_defaults.site }}"
tenant: xxx
tags: "{{ latvia_defaults.tags }}" |
@rodvand ? |
Guys, how do I use it now? Documentation has not been updated with your changes. |
I believe the example you posted @artiomello with |
- name: Office Data Center
description: Office building
location:
name: Office Data Center
site: "{{ latvia_defaults.site }}"
tenant: xxx
tags: "{{ latvia_defaults.tags }}" Might also work although I have not tested it |
Actually, the original code works as expected without adding any additional subkeys. - name: Office Data Center
description: Office building
site: "{{ latvia_defaults.site }}"
tenant: xxx
tags: "{{ latvia_defaults.tags }}" I must say, however, that the lack of explicit up-to-date documentation and ignoring questions and tickets for weeks seems as a rather.. half-hearted attempt at maintaining this whole thing. Community or not. Thanks for your comments though, @sc68cal, appreciate it. |
We are not ignoring you. While I cannot speak for the other maintainers, I am helping on this project when I have spare moments. I am sure they have similar situations. I do not have the ability to contribute to this project full time. Your comments are hurtful and cause harm, and I would ask for your apology. |
Ansible NetBox Collection version
v3.11
Ansible version
Running in AWX. Version is irrelevant to the case.
NetBox version
3.3.7
Python version
3.8
Steps to Reproduce
When trying to create new location in a new site using netbox.netbox.netbox_location module updates existing locations with the same name, even though they are located in a different site, instead of creating new ones with their own separate site.
Locations are created like so:
with looped locations defined in the following way:
Expected Behavior
Existing locations with the same name but different sites should stay unchanged and previously undefined site/location pairs should be created properly instead.
Observed Behavior
Because I already have a location named "Office Data Center" within a different site, e.g. "Riga", what actually happens is that the latter location in Riga gets updated (its site is effectively changed from Riga to Marupe) instead of a new one in Marupe being created.
The text was updated successfully, but these errors were encountered: