Galaxy Role Import: Namespace & GitHub User / Org Mismatch

Summary

This guide explains how to successfully import your role into galaxy.ansible.com when the role namespace name and GitHub user or organization slug do not match.

For example, the GitHub organization slug is my-amazingorg but the role namespace name is my_amazingorg.

Import Symptoms

When using the ansible-galaxy role import command you may see HTTP 500 internal server errors from Galaxy:

[ERROR]: None (HTTP Code: 500, Message: Internal Server Error)

Furthermore, you may see an error similar to below in the Galaxy tasks:

===== CLONING REPO =====
...
fatal: could not read Username for 'https://github.com': terminal prompts disabled

Resolution: Galaxy REST API

You can import your role using the Galaxy REST API directly.

  1. Ensure your role’s meta/main.yml galaxy_info.namespace value matches the destination role namespace on Galaxy:

    # meta/main.yml
    galaxy_info:
     # Replace with your role namespace name
     namespace: my_amazingorg
    
  2. Retrieve your Galaxy token.

  3. Place your Galaxy token into a variable:

     GALAXY_TOKEN="<Token from step 2>"
    
  4. Use the following command to import the role, modifying github_repo, github_user and alternate_clone_url:

    curl -X 'POST' \
      "https://galaxy.ansible.com/api/v1/imports/" \
      -H 'Accept: application/json' \
      -H "Authorization: Token ${GALAXY_TOKEN}" \
      --data-raw '{"github_repo": "ansible-role-hello-world", "github_user": "my_amazingorg", "alternate_clone_url": "https://github.com/my-amazingorg/ansible-role-hello-world"}'
    

References