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

Update AWX collection to use basic authentication #15554

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

ldjebran
Copy link

@ldjebran ldjebran commented Sep 27, 2024

SUMMARY

Update AWX collection to use basic authentication when collection_type is awx,
else try to create a token from gateway and controller when failed todo so use basic authentication instead.

ISSUE TYPE
  • New or Enhanced Feature
COMPONENT NAME
  • Collection
AWX VERSION
awx: 24.6.2.dev122+g4ce2947dcf
ADDITIONAL INFORMATION

Tested when connected to awx service with _COLLETION_TYPE ="awx"

- name: Test collection with auth
  hosts: localhost
  connection: local
  become: false
  gather_facts: false
  vars:
    controller_host: https://localhost:8043
    source_job_template_name: "Demo Job Template"
    job_template_name: "Demo Job Template 1"
    organization: Default
    controller_username: admin
    controller_password: <hidden-awx-admin-password>
  tasks:
    - name: Create a copy of Demo Job Template
      awx.awx.job_template:
        controller_host: "{{ controller_host }}"
        validate_certs: false
        controller_username: "{{ controller_username }}"
        controller_password: "{{ controller_password }}"
        organization: "{{ organization }}"
        copy_from: "{{ source_job_template_name }}"
        name: "{{ job_template_name }}"
        state: exists
      register: demo_template_copy

    - name: Delete the copy of Demo Job Template
      awx.awx.job_template:
        controller_host: "{{ controller_host }}"
        validate_certs: false
        controller_username: "{{ controller_username }}"
        controller_password: "{{ controller_password }}"
        organization: "{{ organization }}"
        name: "{{ job_template_name }}"
        state: absent

    - name: Try to copy a template with non existent user
      awx.awx.job_template:
        controller_host: "{{ controller_host }}"
        validate_certs: false
        controller_username: does_not_exit
        controller_password: any-password
        organization: "{{ organization }}"
        copy_from: "{{ source_job_template_name }}"
        name: "{{ job_template_name }}"
        state: exists
      register: response
      failed_when: '"Failed to get user info: HTTP Error 401: Unauthorized" not in response.msg'
$ ansible-playbook test_collection_awx.yml
does not match 'all'

PLAY [Test collection with auth] ***********************************************************************

TASK [Create a copy of Demo Job Template] **************************************************************
changed: [localhost]

TASK [Delete the copy of Demo Job Template] ************************************************************
changed: [localhost]

TASK [Try to copy a template with non existent user] ****************************************************
ok: [localhost]

PLAY RECAP *********************************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Tested when connected to proxy with _COLLETION_TYPE ="tower"

- name: Test controller with proxy gateway
  hosts: localhost
  connection: local
  become: false
  gather_facts: false
  vars:
    controller_host: https://localhost
    source_job_template_name: "Demo Job Template"
    job_template_name: "Demo Job Template 1"
    organization: Default
    controller_username: admin
    controller_password: <hidden-gateway-admin-password>
# same content as first one     

Result

$ ansible-playbook test_collection_proxy.yml 
PLAY [Test controller with proxy gateway] **************************************************************

TASK [Create a copy of Demo Job Template] **************************************************************
changed: [localhost]

TASK [Delete the copy of Demo Job Template] ************************************************************
changed: [localhost]

TASK [Try to copy a template with non existent user] ***************************************************
[WARNING]: url: https://localhost/api/gateway/v1/tokens/ - Failed to get token: HTTP Error 401:
Unauthorized
[WARNING]: url: https://localhost/api/controller/v2/tokens/ - Failed to get token: HTTP Error 401:
Unauthorized
ok: [localhost]

PLAY RECAP *********************************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

@github-actions github-actions bot added component:awx_collection issues related to the collection for controlling AWX community labels Sep 27, 2024
@ldjebran ldjebran force-pushed the awx-update-awx-collection-basic-auth branch from 4ce2947 to 8e8b94f Compare September 27, 2024 09:59
@ldjebran ldjebran force-pushed the awx-update-awx-collection-basic-auth branch 8 times, most recently from b697078 to dd58af3 Compare September 30, 2024 11:56
@ldjebran ldjebran force-pushed the awx-update-awx-collection-basic-auth branch 6 times, most recently from f390da9 to 4bd34d9 Compare October 3, 2024 07:47
Update AWX collection to use basic authentication when oauth token not provided,
and when username and password provided.
@ldjebran ldjebran force-pushed the awx-update-awx-collection-basic-auth branch from 4bd34d9 to 263d82f Compare October 3, 2024 07:50
Copy link

sonarcloud bot commented Oct 3, 2024

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.

3 participants