How to automate "adding" a collection to a custom repository in Automation Hub/Galaxy_NG

I’m working with a semi-air-gapped installation of Galaxy_NG:4.8.1, and have automated a process of downloading collection tars from galaxy.ansible.com and uploading them to the private hub’s community repository. The redhat certified/validated content repositories are not blocked by firewall, so those are synced directly, while the community repository remote source is blocked. The current list of collections I’m “manually syncing” from the community repository are based on https://github.com/ansible-community/ansible-build-data/tree/main/7/galaxy-equirements.yml, but I run into errors when trying to upload artifacts that already exist in rh-certified (such as the ansible.* collections).

There is a process in the UI to copy collections between repositories.

  1. Log in to hub
  2. Navigate to Collections → Repositories
  3. Locate your destination repository and click the [More Actions] icon (3 vertical dots); then select Edit
  4. Select the Collections version tab.
  5. Click [Add Collection] and select the collections that you want to add to the repository.
  6. Click [Select].

I would like to ensure all of the collections I require from the community upstream is synced to the local community repository, even if the artifact is already in another repository. While I could manually do this in the UI, that’s very tedious. Is there a way to automate the “Add Collection” function through the API? I’m having a hard time finding this specific function in the swagger-ui, but I feel like it may be because the api path is counter-intuitive to the UI’s process.

Answering my own question in case anyone else comes looking here.

There is an api path for moving and copying collections between repositories, where {source_path} and {dest_path} are the repository names:

copy

POST /api/galaxy/v3/collections/{namespace}/{name}/versions/{version}/copy/{source_path}/{dest_path}/

move

POST /api/galaxy/v3/collections/{namespace}/{name}/versions/{version}/move/{source_path}/{dest_path}/

3 Likes

One slight correction… source_path & dest_path correspond to a base_path of a distribution pointing to the repository, not the repository name.

They will only be the same if you create them that way, the UI will do that by default as long as the repository name doesn’t have spaces or other special chars, and as long as a distribution with that name doesn’t already exist, and the base_path is not already taken.

(You might also like to know that the collection upload issue should be fixed in Change duplicate collection uploads to use Pulp retrieval logic by gerrod3 · Pull Request #1692 · pulp/pulp_ansible · GitHub, just not released yet.)

2 Likes

That would certainly be nice if Galaxy will automatically associate existing/matching artifacts with new uploads to the destined repositories, especially if it works with “orphaned” artifacts.

1 Like

Looks like Galaxy_NG just needs to bump the requirements to pulp-ansible==0.20.3, but I don’t know if there are other changes that would need to be made.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.