redhat-cop / infra-ansible

Tooling / Ansible to support the many aspects of infrastructure installation, setup and configuration.
Apache License 2.0
214 stars 120 forks source link

Ansible Tower: Fix missing organization_id #632

Closed MAHDTech closed 3 years ago

MAHDTech commented 3 years ago

What does this PR do?

Role: roles/ansible/tower/manage-organizations

During first-time execution against a new Ansible Tower installation, once the initial REST result is captured there is no organization_id for those yet to be created that are being passed as params.

This results in an empty organization_id variable for the ansible galaxy credentials task which is directly below.

This change adds a second query once any new organizations have been added, so the organization_id is populated, as well as skipping the galaxy credentials on the first run.

How should this be tested?

Run the playbook against a blank Ansible Tower with only the default organization and with user defined organizations.

Is there a relevant Issue open for this?

Nope

Other Relevant info, PRs, etc.

Perhaps I'm missing an additional playbook or doing something out of the norm, however I've tested the non-modified playbook a few times and the error is consistent.

For testing I have been using;

People to notify

cc: @redhat-cop/infra-ansible

oybed commented 3 years ago

This solution seems to add quite a bit of overhead for something that it seems that we are just missing the organization_id for newly added orgs. IMHO a better solution would be to see if we can obtain the organization_id after we just added the org and hence make the credential step below work as expected.

It's been awhile since I looked at the return values from this uri call, but if we are lucky, perhaps the org_id is returned as part of the content return value from uri(?)

MAHDTech commented 3 years ago

@oybed, yes you're correct. I've checked the return values and the organization id is part of the response.

I've modified the change to make use of that field, simplying the change in the process and reducing the number of required API calls.