Skip to content
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

use optional api prefix in collection if set as environ vairable #15205

Merged
merged 2 commits into from
May 29, 2024

Conversation

Harshith-umesh
Copy link
Contributor

@Harshith-umesh Harshith-umesh commented May 20, 2024

SUMMARY

This change make the collection compatible with OPTIONAL_API_URLPATTERN_PREFIX environment variable.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • Collection
ADDITIONAL INFORMATION

Testing:
To test this change I cloned the awx repo, made the change in the controller_api.py file and created a basic ansible playbook which references the updated awx code. The playbook launches a job against the controller. The playbook looks like this:

- hosts: localhost
  gather_facts: false
  environment: 
    CONTROLLER_OPTIONAL_API_URLPATTERN_PREFIX: '/api/controller/'
  tasks: 
    - name: Launch a job on controller
      awx.awx.job_launch:
        job_template: 7
        controller_password: 'SECRET'
        controller_host: 'https://my.controller.com'
        controller_username: 'admin'
      register: job
   
    - name: Wait for controller job
      awx.awx.job_wait:
        job_id: "{{ job.id }}"
        controller_password: 'SECRET'
        controller_host: 'https://my.controller.com'
        controller_username: 'admin'
        timeout: 120

to run the playbook i ran the following command:
ansible-playbook -i localhost, play.yml -e ansible_connection=local

@github-actions github-actions bot added component:awx_collection issues related to the collection for controlling AWX community labels May 20, 2024
@kdelee kdelee changed the title use optional api prefix if set as environ vairable use optional api prefix incollection if set as environ vairable May 20, 2024
@kdelee kdelee changed the title use optional api prefix incollection if set as environ vairable use optional api prefix in collection if set as environ vairable May 20, 2024
@chadmf
Copy link
Collaborator

chadmf commented May 21, 2024

I like this method as it leaves us open in the future to add other vars. LGTM!

@chadmf
Copy link
Collaborator

chadmf commented May 21, 2024

Also will the API be referenceable as a variable in the collection itself?

@kdelee
Copy link
Member

kdelee commented May 21, 2024

@chadmf not sure what you mean. These changes are to a base class ControllerModule that the other modules build off of. So attributes/functions on this base class are used by them unless overriden

@chadmf
Copy link
Collaborator

chadmf commented May 21, 2024

Ah yeah sorry my brain went straight to the collection

@AlanCoding
Copy link
Member

I'm just a little surprised, why would we only respect this only as an environment variable as opposed to treating it as a config variable like all the others (like host, username, verify_ssl, etc.), which can also be given as environment vars.

@Harshith-umesh
Copy link
Contributor Author

Harshith-umesh commented May 22, 2024

Updated the logic to detect if run using upstream awx or downstream controller. There was a variable called self._COLLECTION_TYPE that is used to determine what the collection type and is set at build time.

- name: Set the collection type in the controller_api.py file
replace:
path: "{{ collection_path }}/plugins/module_utils/controller_api.py"
regexp: '^ _COLLECTION_TYPE = "awx"'
replace: ' _COLLECTION_TYPE = "{{ collection_package }}"'

Tested it out by changing this line

and it worked against downstream deployment without having to set the environment variable.
PTAL

@kdelee kdelee merged commit 776b661 into ansible:devel May 29, 2024
21 checks passed
djyasin pushed a commit to djyasin/awx that referenced this pull request Sep 16, 2024
…ible#15205)

* use optional api prefix if set as environ variable

* Different default depending on collection type
djyasin pushed a commit to djyasin/awx that referenced this pull request Nov 11, 2024
…ible#15205)

* use optional api prefix if set as environ variable

* Different default depending on collection type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community component:awx_collection issues related to the collection for controlling AWX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants