ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
13.96k stars 3.41k forks source link

awx.awx.organization fails when new_name is set and organisation already got renamed #15572

Open bartowl opened 1 day ago

bartowl commented 1 day ago

Please confirm the following

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

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?

bartowl commented 1 day ago

Forgot to mention, I use version awx.awx:24.6.1 of the collection.

Main question is - is this wanted behaviour, or a bug. If this is indeed a bug I could provide PR against this and potentialy other modules having new_name