-
Notifications
You must be signed in to change notification settings - Fork 332
Add the ability to rename objects #1447
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1447 +/- ##
==========================================
+ Coverage 78.78% 78.99% +0.21%
==========================================
Files 47 47
Lines 5901 5946 +45
Branches 1515 1535 +20
==========================================
+ Hits 4649 4697 +48
Misses 769 769
+ Partials 483 480 -3 ☔ View full report in Codecov by Sentry. |
|
I don't understand how this can be idempotent. If I run the module, it will change the name the first time. If I rerun the module it will fail because the original name that it's looking for is no longer there. How often do you rename things? It just seems like its bad ansible practice in general. |
|
I agree it kind of leaves a bad taste in my mouth, but it seems like we should be able rename an object without deleting it and recreating it, especially because the Zabbix API supports it. I don't rename things every day, but I probably have renamed things a couple dozen times over the last year |
It seems like an edge case to me where I would normally say leave it out but I like your idea. It's similar to how Ansible handles the cmd module. My suggestion would be check and see if the new name is there, and if so no change. If it's not, then look for the old name and then change it/or fail. Please add a test case into the module integration tests as well. |
|
Okay, I've changed it so if the new_name is already used, the module will return OK rather than failing and added unit tests to verify that |
SUMMARY
Adds the ability to rename objects in Zabbix
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
Currently the only way to rename resources using the Ansible modules is to delete the resource under the old name and recreate it under the new name, despite that the Zabbix API supports renaming these types of resources.
The UID for these resources from the API's point of view is a number, not the name. As that's not very user friendly, when I wrote the modules, I use the resource name and the host/template name to lookup the ID. Unfortunately, the side effect of this is if you try to rename a resource, the module will try to create a duplicate resource with the new name
I've been using the above work around of deleting and recreating, but that has its own unfortunate side-effect that you lose the historical data
This PR adds a new_name parameter like below:
In this example, the module lookup the itemid for a Zabbix item with the name
agent_pingin the templateexample_template. It will then set the name field for the item with the id tonew_agent_ping