# How to automate "adding" a collection to a custom repository in Automation Hub/Galaxy\_NG

**URL:** <https://forum.ansible.com/t/how-to-automate-adding-a-collection-to-a-custom-repository-in-automation-hub-galaxy-ng/3178>\
**Category:** Get Help\
**Tags:** api, galaxy-ng\
**Created:** [January 5, 2024, 3:34pm UTC](https://forum.ansible.com/t/how-to-automate-adding-a-collection-to-a-custom-repository-in-automation-hub-galaxy-ng/3178 "2024-01-05T15:34:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [January 5, 2024, 3:34pm UTC](https://forum.ansible.com/t/how-to-automate-adding-a-collection-to-a-custom-repository-in-automation-hub-galaxy-ng/3178/1 "2024-01-05T15:34:49Z")

</div>

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](http://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](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.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [January 5, 2024, 4:06pm UTC](https://forum.ansible.com/t/how-to-automate-adding-a-collection-to-a-custom-repository-in-automation-hub-galaxy-ng/3178/2 "2024-01-05T16:06:25Z")

</div>

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}/

---

<div class="post-metadata">

**Author:** ![himdel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/himdel/32/581_2.png) [@himdel](https://forum.ansible.com/u/himdel)\
**Post date:** [January 5, 2024, 6:43pm UTC](https://forum.ansible.com/t/how-to-automate-adding-a-collection-to-a-custom-repository-in-automation-hub-galaxy-ng/3178/3 "2024-01-05T18:43:27Z")

</div>

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](https://github.com/ansible/ansible-hub-ui/blob/master/src/containers/ansible-repository/edit.tsx#L136-L155) 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](https://github.com/pulp/pulp_ansible/issues/1692), just not released yet.)

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [January 7, 2024, 4:07pm UTC](https://forum.ansible.com/t/how-to-automate-adding-a-collection-to-a-custom-repository-in-automation-hub-galaxy-ng/3178/4 "2024-01-07T16:07:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [January 17, 2024, 8:07pm UTC](https://forum.ansible.com/t/how-to-automate-adding-a-collection-to-a-custom-repository-in-automation-hub-galaxy-ng/3178/5 "2024-01-17T20:07:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 28, 2024, 3:33pm UTC](https://forum.ansible.com/t/how-to-automate-adding-a-collection-to-a-custom-repository-in-automation-hub-galaxy-ng/3178/6 "2024-03-28T15:33:33Z")

</div>

Closed on March 28, 2024, 3:33pm UTC

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