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.93k stars 3.41k forks source link

Galaxy named servers #13323

Open SJay3 opened 1 year ago

SJay3 commented 1 year ago

Please confirm the following

Bug Summary

Unable to use named galaxy servers in awx.

Now, if you have more than one galaxy servers in awx, when project sync job is running it gets the following environment variables: ANSIBLE_GALAXY_SERVER_LIST="server0,server1" ANSIBLE_GALAXY_SERVER_SERVER0_URL="url" ANSIBLE_GALAXY_SERVER_SERVER0_TOEKN="token" ANSIBLE_GALAXY_SERVER_SERVER1_URL="url2" ANSIBLE_GALAXY_SERVER_SERVER2_TOKEN-"token2"

We need to support named galaxy servers in awx. It means that awx should set the following environment variables ANSIBLE_GALAXY_SERVER_LIST="MyLocalCoolServer,Global_server" ANSIBLE_GALAXY_SERVER_MYLOCALCOOLSERVER_URL="..." ANSIBLE_GALAXY_SERVER_GLOCAL_SERVER_URL="..."

AWX version

19.5.0

Select the relevant components

Installation method

kubernetes

Modifications

no

Ansible version

No response

Operating system

No response

Web browser

No response

Steps to reproduce

ansible.cfg

[galaxy]
server_list = local, global

[galaxy_server.local]
url=https://local.galaxy-ng.example.net/api/galaxy/
token = "myToken"

[galaxy_server.global]
url=https://proxy.galaxy.example.net/repository/galaxy/

requirements.yml

---

collections:
  - name: "community.general"
    version: "*"
    source: "global"
  - name: "community.hashi_vault"
    version: "*"
    source: "global"
  - name: "my.authomatization"
    version: "1.8.0"
    source: "local"

When you manual run ansible-galaxy collections install -r requirements.yml everything works fine.

Setup this galaxy servers in awx as global and local, add galaxy servers to organization, then sync project.

Expected results

In project sync job we have envs: ANSIBLE_GALAXY_SERVER_LIST="local,global" ANSIBLE_GALAXY_SERVER_LOCAL_URL="..." ANSIBLE_GALAXY_SERVER_GLOBAL_URL="..."

Actual results

ANSIBLE_GALAXY_SERVER_LIST="server0,server1" ANSIBLE_GALAXY_SERVER_SERVER0_URL="url" ANSIBLE_GALAXY_SERVER_SERVER0_TOEKN="token" ANSIBLE_GALAXY_SERVER_SERVER1_URL="url2" ANSIBLE_GALAXY_SERVER_SERVER2_TOKEN-"token2"

Additional information

Problem in this code https://github.com/ansible/awx/blob/devel/awx/main/tasks/jobs.py#L1154

        galaxy_server_list = []
        if project_update.project.organization:
            for i, cred in enumerate(project_update.project.organization.galaxy_credentials.all()):
                env[f'ANSIBLE_GALAXY_SERVER_SERVER{i}_URL'] = cred.get_input('url')
                auth_url = cred.get_input('auth_url', default=None)
                token = cred.get_input('token', default=None)
                if token:
                    env[f'ANSIBLE_GALAXY_SERVER_SERVER{i}_TOKEN'] = token
                if auth_url:
                    env[f'ANSIBLE_GALAXY_SERVER_SERVER{i}_AUTH_URL'] = auth_url
                galaxy_server_list.append(f'server{i}')

when we build env variables for galaxy, we do not use name of galaxy credentials. I thing we could use credentials name. It looks like easy to fix

akus062381 commented 1 year ago

Hi @SJay3,

Thank you for opening this issue and being part of our community!

Is there any reason why you can't use the Galaxy credential types inside of AWX? They are designed to do specifically what you are after.

SJay3 commented 1 year ago

Hi @akus062381, No, we use Galaxy credentials in AWX. It works fine, but my question is about named galaxy credentials. If we create requirements.yml with source field it works in ansible directly, but didn't work in AWX. It happens because AWX set ansible environments as "server0,server1" instead of use named credentials, ex. "local,global"