How to create a new role on Ansible Galaxy?

Hi! I’d like to publish a role on ansible galaxy. I made an account and a “caboteria” namespace (I had a link but I’m a new user so that caused my post to be rejected)

The namespace says that roles will appear when I import them, so I chose the “Import role” option from the menu in the upper right.

The role code is at GitHub - caboteria/ansible-role-firefox at deb and it’s a fork of an existing role.

On the role page I entered the following:

  • GH user: caboteria
  • GH repo: ansible-role-firefox
  • GH ref: deb (I want to import from a branch)
  • Namespace name: caboteria (the namespace in the metadata is different but I’m making a fork)
  • Role name: firefox (not sure if this is needed)

The “Will clone” link is correct, it points to the repo.

Click “Import”, then go to https: //galaxy.ansible.com/ui/standalone/imports/. It says the import failed in 5 hours but I think that’s a timezone bug since it failed immediately.

The error message is:

Starting import: task_id=2062671229682731134284557851035589725, pulp_id=018d418b-1840-77e7-bacd-54fc203e5c5d 
 
==== PARAMETERS ==== 
importer username: caboteria 
matched user: caboteria id:21984 
github_user: caboteria 
github_repo: ansible-role-firefox 
github_reference: deb 
alternate_clone_url: None 
alternate_namespace_name: caboteria 
alternate_role_name: firefox 
 
==== CHECK FOR MATCHING ROLE(S) ==== 
user:caboteria repo:ansible-role-firefox did not match any existing roles 
 
===== CLONING REPO ===== 
cloning https://github.com/caboteria/ansible-role-firefox ... 

Failed

I’m not sure what “did not match any existing roles” means since I’m trying to create a new role. Do I need to “create” a role before I can import it?

Thank you for your help!

PS. Got an error when I tried to submit the post saying that new users can only submit two links. This makes it difficult to provide the relevant data.

I see that some successful imports say “did not match any existing roles” so that might be a red herring, in which case the sum of the error information is the word “Failed”.

I tried cloning the URL in the “cloning” message and that worked.

Hi,

I have just tried to import a new role in Galaxy. I got a similar result as the original poster here. In other words, the results were like this:

==== CHECK FOR MATCHING ROLE(S) ====
user:caboteria repo:ansible-role-firefox did not match any existing roles

===== CLONING REPO =====
cloning GitHub - caboteria/ansible-role-firefox: Firefox Installation.

Failed

It simply says “Failed”.

Without providing a detailed error message, beyond that.

The last message before “Failed” is “CLONING REPO”.

It’s doubtful that cloning is failing.

If it is, could there be a message that says “Attempted to clone ___ , however this error occurred ____”

Otherwise… why is there no information at all whatsoever, accompanying the “Failed” error?

The full import log as shown on galaxy is …

Starting import: task_id=2066339790802179135560782483496035499, pulp_id=018df66a-d88a-710c-95de-a71796a6e4ab 
 
==== PARAMETERS ==== 
importer username: sdarwin 
matched user: sdarwin id:5993 
github_user: sdarwin 
github_repo: ansible-stagesync 
github_reference: galaxy 
alternate_clone_url: None 
alternate_namespace_name: None 
alternate_role_name: None 
 
==== CHECK FOR MATCHING ROLE(S) ==== 
user:sdarwin repo:ansible-stagesync did not match any existing roles 
 
===== CLONING REPO ===== 
cloning https://github.com/sdarwin/ansible-stagesync ... 

Failed

However, when I view the regular task view (v1 tasks are a compatibility layer around pulp tasks) Ansible Galaxy I see further context …

Description
galaxy is not a valid branch or tag name

Traceback
  File "/venv/lib64/python3.11/site-packages/pulpcore/tasking/tasks.py", line 66, in _execute_task
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/app/galaxy_ng/app/api/v1/tasks.py", line 409, in legacy_role_import
    do_git_checkout(clone_url, checkout_path, github_reference)
  File "/app/galaxy_ng/app/api/v1/tasks.py", line 148, in do_git_checkout
    raise Exception(f'{github_reference} is not a valid branch or tag name')

I’m not sure how you are starting your imports, but you are specifying the branch is “galaxy” somehow and that is what’s causing the import to fail. The first log specifies the input branch via the “github_reference” parameter. This is specified via --branch on the ansible-galaxy command line or the GitHub ref field in the web UI’s import form.

@tannerjc thanks!! It was a “galaxy” branch, which existed locally however had not been pushed up to GitHub.

Is there an import screen in the UI? Instead of the ansible-galaxy cli. If so, what is the link ?

I didn’t know “Task Management” existed. You could display a hyperlink from a role import to it’s Task, especially in the case of an error.

Ideally to the exact Task.

Otherwise, just a global text message: “For more information about this error, refer to the Task Management section of the UI”.

Here’s another different issue. or not? See below.

ansible-galaxy role import --help
...
  --token API_KEY, --api-key API_KEY
                        The Ansible Galaxy API key which can be found at https://galaxy.ansible.com/me/preferences.
...

It directs the user to https://galaxy.ansible.com/me/preferences , which results in “404 - Page not found”

The problem is that this block of code doesn’t log an error before throwing the exception, which is why you don’t see it in the normal import log …

We need to fix that in the code so that people see the error during import.

We don’t have a hyperlink, but the pulp id for the import task is listed at the beginning of the log. It’s a UUID rather than an integer and with that you can get to Ansible Galaxy<PULP_ID>/ if you have the right permissions. I’m not sure that regular users can see these pages though.

In the roles section of the UI there’s a blue button for “import role” which takes you to this page Ansible Galaxy

there’s a blue button

Awesome! I had looked around for that before. Very glad to see it. The user guide says “Role imports are only supported through the ansible galaxy cli.”

the pulp id for the import task is listed at the beginning of the log.

Right.