How to Import ansible role on galaxy.ansible.com

Hi everyone.

Since ansible galaxy somehow morphed into galaxy-ng, I can’t figure out how to update my ansible content there or upload new roles. It feels like ansible roles are no longer wanted or supported.

Most of the time I have been using robertdebock’s gh action from https://github.com/marketplace/actions/publish-ansible-role-to-galaxy. This uses the ansible-galaxy tool.

 ansible-galaxy role import \
   --api-key ${galaxy_api_key} \
   --branch ${git_branch} \
   $(echo $GITHUB_REPOSITORY | cut -d/ -f1) \
   $(echo $GITHUB_REPOSITORY | cut -d/ -f2)

Unfortunately, this no longer works. I tried doing it manually via the CLI, but I cannot figure out how to work with the ``ansible-galaxy role import’’ command.

I tried updating the l3d.gopass role from https://github.com/roles-ansible/ansible_role_gopass

ansible-galaxy role import --token (redacted) --verbose --branch main --role-name gopass roles-ansible ansible_role_gopass
No config file found; using defaults
ERROR! None (HTTP Code: 403, Message: Forbidden)

Does anyone have any more information on this? Do I have to put each role into a collection to get it into galaxy-ng? How do I manage the roles from my namespaces l3d (galaxy /ui/standalone/namespaces/9259/), do1jlr (galaxy /ui/standalone/namespaces/8798/) and DO1JLR (galaxy /ui/standalone/namespaces/10239/).

And why are some namespaces case sensitive and others not?

4 Likes

Another thought I had:

Are there different tokens for API V1 (used for ansible roles) and API V3 (used for collections). Because I am currently using the API token from Galaxy NG.

Yeah, I’m running into similar issues. I will let you know if I figure it out with the related solution.

2 Likes

I looked in the API and it looks like there are some options to managed roles. See
https://galaxy.ansible.com/api/v3/swagger-ui/#/Roles

But I did not test it, I just saw it and got distracted by other tasks…

I was able to successfully import.

Had to generate a token and create a local ansible.cfg User Guide - Galaxy NG

$ ansible-galaxy role import -vv --branch master github_user github_repo

2 Likes

Nice it worked for you.

Sadly it is still not working form me.

 $ ansible-galaxy role import -vv --branch main roles-ansible ansible_role_gopass
ansible-galaxy [core 2.15.4]
  config file = /tmp/ansible/ansible.cfg
  configured module search path = ['/home/l3d/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /tmp/ansible/venv/lib/python3.11/site-packages/ansible
  ansible collection location = /home/l3d/.ansible/collections:/usr/share/ansible/collections
  executable location = /tmp/ansible/venv/bin/ansible-galaxy
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/tmp/ansible/venv/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
Using /tmp/ansible/ansible.cfg as config file
ERROR! None (HTTP Code: 403, Message: Forbidden)

Maybe because my ansible roles are in a organisation and not in a user repo. :face_with_diagonal_mouth:

I hit a similar issue when two namespaces appeared for our roles after the migration to NG.

When I try an import, I either hit a 403 or an ugly Python exception.

I filed issue Roles namespace has changed with the new Galaxy website · Issue #3253 · ansible/galaxy · GitHub.

1 Like

Thanks for cross-posting here. We are investigating some strangeness with namespace migration right now. This report is helpful.

Investigating the import issues too @L3D, thanks for the detailed notes.

Also apologies about the issues you all are experiencing.

3 Likes

+1 here on this issue. I am also getting the 403 Forbidden error message.

Getting the error that the token is malformed in the config file but I also get the same 403 when I specify the token as a command line option.

ansible-galaxy [core 2.13.3]
config file = /etc/ansible/ansible.cfg
python version = 3.9.18 (main, Aug 24 2023, 18:16:58) [Clang 15.0.0 (clang-1500.0.40.1)]
jinja version = 3.1.2
libyaml = True
Using /etc/ansible/ansible.cfg as config file
Opened /Users/ryanhennessy/.ansible/galaxy_token
Galaxy token file /Users/ryanhennessy/.ansible/galaxy_token malformed, unable to read it
ERROR! None (HTTP Code: 403, Message: Forbidden)

2 Likes

Did you have anything inside the ansible.cfg file?

This is what I used, but definitely copy it at your own discretion. Not 100% sure on the correctness.

$ cat ~/.ansible.cfg
[galaxy]
server_list = beta

[galaxy_server.beta]
url = https://galaxy.ansible.com/api/
token = my_token
1 Like

I had what Sean Combs suggested below in the ansible.cfg file and it did not work. I also tried with all that content commented out and that provided the same error message.

1 Like

Sean thanks for the update. I tried setting up everything again and now it works!

@L3D I believe I have fixed the problem. Assuming your github login is “DO1JLR” and the github org|user your roles are hosted in is “roles-ansible”, you should now be able to publish in the the “roles-ansible” legacy namespace.

[jtanner@corsair ~]$ curl -s https://galaxy.ansible.com/api/v1/namespaces/?name=roles-ansible | jq .
{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 1858,
      "url": "",
      "summary_fields": {
        "owners": [
          {
            "id": 1884,
            "username": "DO1JLR"
          }
        ],
        "provider_namespaces": [
          {
            "id": 20264,
            "name": "roles_ansible",
            "pulp_href": "/api/pulp/api/v3/pulp_ansible/namespaces/20264/"
          }
        ]
      },
      "created": "2023-05-08T20:42:25.091016Z",
      "modified": "2023-10-06T03:22:23.211444Z",
      "name": "roles-ansible",
      "avatar_url": "https://github.com/roles-ansible.png",
      "related": {
        "provider_namespaces": null,
        "content": null,
        "owners": "/api/v1/namespaces/1858/owners/"
      }
    }
  ]
}

3 Likes

Thanks @tannerjc

Is there a way to use the “l3d” namespace instead of the “roles-ansible” namespace?

Other thing I found out: Ansible role legacy imports fails, when there is no new tag/release. It’s okay, I can work with taht. but is was different in the old galaxy.

It still is weird with these ansible roles.

Just now I released a new version of the l3d.gitea role. See Release v3.3.2 · roles-ansible/ansible_role_gitea · GitHub

The Github Action uploaded it to ansible galaxy. At least the log is telling so:

ansible-galaxy role import --api-key *** --branch main roles-ansible ansible_role_gitea
Successfully submitted import request 2052571993052632521410160482269259626
running
role imported successfully

On galaxy-ng, i found two versions of this role:

https://galaxy.ansible.com/ui/standalone/roles/l3d/gitea/
https://galaxy.ansible.com/ui/standalone/roles/roles-ansible/gitea/

both have Version v3.3.0 instead of v3.3.2.

And the UI is a little bit broken too, see:

If anyone has any clue what really is happening here and if my release v3.3.2 is on galaxy-ng, please contact me. :kissing_heart:

FYI it seems like something is a bit broken currently — I created a new / separate topic for that issue:

2 Likes

The 404 modal shown when clicking on “versions” should be resolved by Remove duplicate trailing slash on fetching legacy role versions and content by jctanner · Pull Request #4424 · ansible/ansible-hub-ui · GitHub once merged and deployed.

3 Likes

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