awx
awx copied to clipboard
awx.awx.organization fails when new_name is set and organisation already got renamed
Please confirm the following
- [X] I agree to follow this project's code of conduct.
- [X] I have checked the current issues for duplicates.
- [X] I understand that AWX is open source software provided for free and that I might not receive a timely response.
- [X] I am NOT reporting a (potential) security vulnerability. (These should be emailed to
[email protected]
instead.)
Bug Summary
The issue happens, when awx.awx.organization is called twice with both name
and new_name
attribute.
First time, the Organization gets renamed properly, but during second run, instead of the task reporting plain 'ok' as no change is needed since the organisation is already renamed it shows following error:
Unable to create organization new_name: {'name': ['Organization with this Name already exists.']}
AWX version
24.6.1
Select the relevant components
- [ ] UI
- [ ] UI (tech preview)
- [ ] API
- [ ] Docs
- [X] Collection
- [ ] CLI
- [ ] Other
Installation method
N/A
Modifications
no
Ansible version
2.15.12
Operating system
Linux
Web browser
Chrome
Steps to reproduce
execute twice following task:
- name: re-name organization
awx.awx.organization:
name: Default
new_name: new_name
Expected results
I would expect this task reports OK, as the change has already been done (for the second and following runs)
Actual results
I get an error:
Unable to create organization Main: {'name': ['Organization with this Name already exists.']}
Additional information
This problem seems to be an easy fix in https://github.com/ansible/awx/blob/ece21b15d06e8108a618ed2f6b5dd85366cc2dcc/awx_collection/plugins/modules/organization.py#L149
just change
organization = module.get_one('organizations', name_or_id=name, check_exists=(state == 'exists'))
to
organization = module.get_one('organizations', name_or_id=name, check_exists=(state == 'exists'))
# check if organization already got renamed
if new_name and not organization:
organization = module.get_one('organizations', name_or_id=new_name, check_exists=(state == 'exists'))
PS. similar issues may affect other modules having new_name attribute. Should I provide PR?