Upload to Galaxy from custom Git server? (not github.com)

I moved my Ansible roles from GitHub to a self-hosted GitLab instance. Is there a way to specify a custom Git server when doing ansible-galaxy role import?

It seems I cannot update my roles on https://galaxy.ansible.com anymore without a GitHub repository.

The import command only seems to support GitHub usernames and repositories:

ansible-galaxy role import --help
usage: ansible-galaxy role import [-h] [-s API_SERVER] [--token API_KEY] [-c] [--timeout TIMEOUT] [-v] [--no-wait] [--branch REFERENCE] [--role-name ROLE_NAME] [--status] github_user github_repo

positional arguments:
  github_user           GitHub username
  github_repo           GitHub repository

with no way to specify a custom repository url/path.

I couldn’t find a related forum thread. Is there a way to update the existing roles in Galaxy?

I do this using a requirements.yml files like this:

- name: apt
  scm: git
  src: https://git.coop/webarch/apt.git
  version: 4.12.1  # apt

I even wrote a role to generate it!

You can use the requirements.yml file like this:

ansible-galaxy install -r requirements.yml --force

Thank you for your input, but I’m looking for a way to keep up-to-date what is uploaded to Ansible Galaxy, meaning as a publisher of a role, not a user.
I updated the thread topic to reflect this better.

1 Like

Ah, sorry for misunderstanding, the way I plan to do this is to push mirror all role repos from GitLab to GitHub, so far I only do this for some:

And then setup GitHub actions to push to Galaxy, this part I haven’t got around to doing but I do recall seeing threads here that explain how to do this.

It’s not possible to upload to Galaxy from a custom Git server. Galaxy does not import the role itself, just metadata about the location and versions, and it constructs the download URL like this galaxy_ng/galaxy_ng/app/api/v1/serializers.py at main · ansible/galaxy_ng · GitHub.

2 Likes

Collections can be published from any server for that only ansible-galaxy command is required. This command is installed with ansible-core

ansible-galaxy collection publish “${COLLECTION_BUILD_FILENAME}” --server “${API_SERVER_ALIAS}”

You have to have ansible.cfg file with server configuration or pass additional parameters to that command. See help for ansible-galaxy command.

Never worked with standalone roles. Probably something similar.

There is no publish option for roles, only import:

ansible-galaxy role --help
usage: ansible-galaxy role [-h] ROLE_ACTION ...

positional arguments:
  ROLE_ACTION
    init       Initialize new role with the base structure of a role.
    remove     Delete roles from roles_path.
    delete     Removes the role from Galaxy. It does not remove or alter the actual GitHub repository.
    list       Show the name and version of each role installed in the roles_path.
    search     Search the Galaxy database by tags, platforms, author and multiple keywords.
    import     Import a role into a galaxy server
    setup      Manage the integration between Galaxy and the given source.
    info       View more details about a specific role.
    install    Install role(s) from file(s), URL(s) or Ansible Galaxy

options:
  -h, --help   show this help message and exit

ansible-galaxy role import --help
usage: ansible-galaxy role import [-h] [-s API_SERVER] [--token API_KEY] [-c] [--timeout TIMEOUT] [-v]
                                  [--no-wait] [--branch REFERENCE] [--role-name ROLE_NAME] [--status]
                                  github_user github_repo

positional arguments:
  github_user           GitHub username
  github_repo           GitHub repository

options:
  -h, --help            show this help message and exit
  -s, --server API_SERVER
                        The Galaxy API server URL
  --token, --api-key API_KEY
                        The Ansible Galaxy API key which can be found at
                        https://galaxy.ansible.com/me/preferences.
  -c, --ignore-certs    Ignore SSL certificate validation errors.
  --timeout TIMEOUT     The time to wait for operations against the galaxy server, defaults to 60s.
  -v, --verbose         Causes Ansible to print more debug messages. Adding multiple -v will increase
                        the verbosity, the builtin plugins currently evaluate up to -vvvvvv. A
                        reasonable level to start is -vvv, connection debugging might require -vvvv.
                        This argument may be specified multiple times.
  --no-wait             Don't wait for import results.
  --branch REFERENCE    The name of a branch to import. Defaults to the repository's default branch
                        (usually master)
  --role-name ROLE_NAME
                        The name the role should have, if different than the repo name
  --status              Check the status of the most recent import request for given
                        github_user/github_repo.

As @shertel wrote you cannot import roles into Galaxy from anywhere except from GitHub. That was a design decision made a long time ago for roles (basically when Galaxy was created), and very likely won’t change.