# Ansible Galaxy’s role import enhancements and fixes for the new year

**URL:** <https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206>\
**Category:** Project Discussions\
**Tags:** ansible-lint, galaxy-ng\
**Created:** [January 8, 2024, 3:59pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206 "2024-01-08T15:59:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 8, 2024, 3:59pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/1 "2024-01-08T15:59:49Z")

</div>

**Ansible Galaxy’s role import enhancements and fixes for the new year.**

**Import logging …**

Remember when you could see a nice formatted list of messages when your roles were imported? We’ve brought that back (see [Role import logging by jctanner · Pull Request #1959 · ansible/galaxy\_ng · GitHub](https://github.com/ansible/galaxy_ng/pull/1959))! You may have already noticed, but when you run “ansible-galaxy role import” it displays colorized messages about what the backend is doing with the role (where it’s cloning from, what lint tests pass or fail, etc). These logs are also displayed in the UI when you visit any role and click on “import log”. We implemented this back in November, but it took a little longer to get the UI changes rolled out.

**Defining a role’s namespace and name …**

_Role import “magic”:_  
For those of you who had roles in the old galaxy with namespaces and names that differ from their related github user and github repo, we implementented some “magic” to route the import to the most “correct” role by namespace and name. While this feature made it possible to keep importing new versions of those roles, it still didn’t address the underlying issue that authors had no way to specify which namespace and name they wanted.

_New standard keys in the meta/main.yml file:_  
`namespace` & `role_name` in meta/main.yml: You can now specify these keys in your meta/main.yml. This means when you’re importing a role, Galaxy will try to slot it into the namespace you’ve mentioned with the role\_name you’ve specified. This makes the role less “portable” in terms of being able to import it into multiple different namespace.name configurations, but it does make the import much more predicatable for those who have namespaces or role names that are different from the github user and github repo. This feature is live in production now and ready to use. Please send us feedback if you have any!

We’ll still keep the “magic” finder code for a while, but it’s only going to trigger if the author hasn’t defined any overrides to the namespace and name.

_New API changes for namespace and name:_

Remember when we could use alternate-role-name in the Galaxy API? It was a nifty feature, but it got dropped a while back (see ansible/galaxy@1d1519f). Since then, the Galaxy gang has been busy bees, adding namespace support in the galaxy-importer schema (ansible/galaxy-importer@98e0931) and slipping in role\_name into the legacy role schema (ansible/galaxy-importer@1927cd6).

As part of [support legacy role import overrides for namespace and name. by jctanner · Pull Request #2011 · ansible/galaxy\_ng · GitHub](https://github.com/ansible/galaxy_ng/pull/2011), we’ve added support in the API for alternate\_namespace\_name and alternate\_role\_name in the POST data for importing a role. If provided, the backend will use these values as the highest order of precedence for determining the namespace+name for the role, regardless of the github user or github repo the role lives in. We don’t suspect many people will use the API directly for importing roles, but the option is avaible. We do plan to use these new parameters to support future enhancements to the UI that allow role authors to import directly into a namespace and or a specific role name. That feature should get us very close to satisfying one of the biggest requests from the community so far.

**UPDATE 2024-01-15**

We’ve built and deployed role upload components to the galaxy UI. You can now import roles from the UI and take advantage of the namespace and name override fields …

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/d/dfa7874e02c6f11f25b4b01bab819a9080830a41.png)

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/7/7ad337b6dfb1575bffedfac9459c541f4955f66e.png)

---

<div class="post-metadata">

**Author:** ![githubixx](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/githubixx/32/1007_2.png) [@githubixx](https://forum.ansible.com/u/githubixx)\
**Post date:** [January 8, 2024, 10:41pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/2 "2024-01-08T22:41:36Z")

</div>

Cloud it be that these changes broke `ansible-galaxy role import ...` again? I was wondering why my `githubixx.kubernetes_controller` role wasn’t updated until I figured out that there is now (again) a new role `githubixx.kubernetes-controller`. That’s actually interesting as `-` are not allowed in role names. `ansible-lint` completely freaks out if you do that 😉 My last import was on Dec 13 and that worked as expected.

This is the Github Action log:

```auto
Run ansible-galaxy role import --api-key *** $(echo githubixx/ansible-role-kubernetes-controller | cut -d/ -f1) $(echo githubixx/ansible-role-kubernetes-controller | cut -d/ -f2)
  
Successfully submitted import request 2060918917000330747058366163679919697
Starting import: task_id=2060918917000330747058366163679919697, pulp_id=018ceb25-cc9a-74bb-a68f-8fa668173e51

==== PARAMETERS ====
importer username: githubixx
matched user: githubixx id:2563
github_user: githubixx
github_repo: ansible-role-kubernetes-controller
github_reference: None
alternate_clone_url: None
alternate_namespace_name: None
alternate_role_name: kubernetes-controller

==== CHECK FOR MATCHING ROLE(S) ====
user:githubixx repo:ansible-role-kubernetes-controller matched existing role githubixx.kubernetes_controller id:32487

===== CLONING REPO =====
cloning https://github.com/githubixx/ansible-role-kubernetes-controller ...

===== GIT ATTRIBUTES =====
github_reference(branch): master
github_commit: 48a7477f08fbbf0214b633fd801de8885f9b1a93
github_commit_message: 23.0.0+1.28.5 (#55)

* upate k8s_release to 1.28.5 / extend enable-admission-plugins list of kube-apiserver

* update CHANGELOG and README

* Molecule: Change IP addresses
github_commit_date: 2024-01-08T23:09:49+01:00

===== LOADING ROLE =====
Importing with galaxy-importer 0.4.18
Determined role name to be kubernetes_controller
Linting role kubernetes_controller via ansible-lint...
ansible-role-kubernetes-controller/molecule/default/prepare.yml:53:7: syntax-check[specific]: couldn't resolve module/action 'ansible.posix.synchronize'. This often indicates a misspelling, missing collection, or incorrect module path.
ansible-role-kubernetes-controller/molecule/default/verify.yml:8:7: syntax-check[specific]: couldn't resolve module/action 'kubernetes.core.k8s_info'. This often indicates a misspelling, missing collection, or incorrect module path.
...ansible-lint run complete
Legacy role loading complete

===== PROCESSING LOADER RESULTS ====
overriding namespace name via metadata: githubixx
enumerated role name kubernetes-controller
created new role id:37622 githubixx.kubernetes-controller

```

I guess `alternate_role_name: kubernetes-controller` is wrong and it’s also not in the metadata. `meta/main.yml` looks like this:

```auto
---
galaxy_info:
  author: Robert Wimmer
  description: Installs the Kubernetes API server, scheduler and controller manager.
  license: GPLv3
  min_ansible_version: "2.9"
  role_name: kubernetes_controller
  namespace: githubixx
  platforms:
    - name: Ubuntu
      versions:
        - "focal"
        - "jammy"
  galaxy_tags:
    - kubernetes
    - scheduler
    - api
    - controller
    - ha

```

The `role_name` also is set to `kubernetes_controller` (with “\_” and not “-”).

So this is the new (and wrongly named) role:  
[https://galaxy.ansible.com/ui/standalone/roles/githubixx/kubernetes-controller/](https://galaxy.ansible.com/ui/standalone/roles/githubixx/kubernetes-controller/)

But it should be imported here:  
[https://galaxy.ansible.com/ui/standalone/roles/githubixx/kubernetes\_controller/](https://galaxy.ansible.com/ui/standalone/roles/githubixx/kubernetes_controller/)

Thanks for checking!

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 8, 2024, 11:18pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/3 "2024-01-08T23:18:43Z")

</div>

I see the issue …

> <https://github.com/ansible/ansible/blob/devel/lib/ansible/galaxy/api.py#L485-L486>

Core is injecting the alternate\_role\_name parameter based on the name of the repository. Based on [Support user defined role names in role metadata only · ansible/galaxy@1d1519f · GitHub](https://github.com/ansible/galaxy/commit/1d1519f) that hasn’t actually done anything in old-galaxy since 2018. However, in new galaxy with the patch I mention in this announcement it has been restored.

In your case, your github action workflow should change to something like …

```auto
ansible-galaxy role import -vvvvvvvv --role-name=$(echo ${{ github.repository }} | cut -d/ -f2 | sed 's/ansible-role-//' | sed 's/-/_/') $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)

```

Passing the `--role-name` will stop core from trying to do the wrong thing.

---

<div class="post-metadata">

**Author:** ![jburel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jburel/32/1951_2.png) [@jburel](https://forum.ansible.com/u/jburel)\
**Post date:** [January 9, 2024, 2:53pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/4 "2024-01-09T14:53:07Z")

</div>

Facing a similar issue when publishing a new version of an existing role via GitHub action.

Do you suggest to apply the work around using `--role-name`?  
Note that this broke all the existing Github actions used to publish to Galaxy e.g. `ansible-actions/ansible-galaxy-action` since none of the existing actions offers the ability to specify the `role-name` as a parameter. So users will be forced to use `ansible-galaxy role import...` command directly.

Or do you suggest to rename the repository to use underscore instead of dash?

Thanks for clarifying that critical issue

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 9, 2024, 3:21pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/5 "2024-01-09T15:21:46Z")

</div>

@jburel in my personal opinion, use `--role-name`. The long term fix (again in my opinion) is for core to remove the code I mentioned in my previous response.

Changing the repository name would also theoretically work, but I sense that not many people would actually want to do that.

---

<div class="post-metadata">

**Author:** ![jburel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jburel/32/1951_2.png) [@jburel](https://forum.ansible.com/u/jburel)\
**Post date:** [January 9, 2024, 3:31pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/6 "2024-01-09T15:31:36Z")

</div>

Thanks for the answer

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [January 9, 2024, 4:52pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/7 "2024-01-09T16:52:04Z")

</div>

This is on my to-do list to fix. Is there any special behavior when uploading a role via the web ui anymore if the role starts with `ansible-role-`? That was the reason it was added in [Allow setting alternate\_role\_name for galaxy CLI (#17418) · ansible/ansible@bd9ca5e · GitHub](https://github.com/ansible/ansible/commit/bd9ca5ef28dff4f788f92bc2068a5a490e7c9be9),

> Also, the web ui is smart and imports  
> “openstack-infra/ansible-role-puppet” as openstack-infra.puppet … but  
> the CLI imports it as openstack-infra.ansible-role-puppet. Add that  
> filtering as well.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 9, 2024, 5:25pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/8 "2024-01-09T17:25:37Z")

</div>

No special behavior anymore. The code to truncate ansible-role- from the repo name no longer exists in the backend.

---

<div class="post-metadata">

**Author:** ![githubixx](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/githubixx/32/1007_2.png) [@githubixx](https://forum.ansible.com/u/githubixx)\
**Post date:** [January 9, 2024, 7:21pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/9 "2024-01-09T19:21:47Z")

</div>

Thanks a lot @tannerjc ! That worked for me.

---

<div class="post-metadata">

**Author:** ![staticdev](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/staticdev/32/1582_2.png) [@staticdev](https://forum.ansible.com/u/staticdev)\
**Post date:** [January 10, 2024, 9:01am UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/10 "2024-01-10T09:01:03Z")

</div>

This is good. I think if you don’t specify a `role_name` on either `meta/main.yml` or `ansible-galaxy`, it doesn’t need to guess and use what you passed as attribute: `github_repo`.

From usage:

```auto
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

```

BUT, the problem is, if you don’t specify `--role-name` on `ansible-galaxy` and specify on `meta/main.yml` it should use the name specified. This is not the case and it creates unnecessary extra breaking change. I propose to have this behavior.

In my case I call ansible-galaxy with:

```sh
ansible-galaxy role import --api-key *** staticdev ansible-role-python-developer

```

But I define on `meta/main.yml` as **python\_developer**. But it is being imported as **python-developer**. This is completely counter-intuitive, I am against having to add additional parameter on the CLI since it is already specified on metadata.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 10, 2024, 3:29pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/11 "2024-01-10T15:29:22Z")

</div>

@staticdev I agree with you. The core team appears to want to make that change here [[ansible-galaxy] Remove role name conversion when the repo startswith 'ansible-role' by s-hertel · Pull Request #82508 · ansible/ansible · GitHub](https://github.com/ansible/ansible/pull/82508) but we’ll have a long while before every supported version of core out in the wild has that patch since it probably won’t be backported.

We’ll have to come up with some way to mitigate the confusion in the meantime.

---

<div class="post-metadata">

**Author:** ![dbrennand](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dbrennand/32/7830_2.png) [@dbrennand](https://forum.ansible.com/u/dbrennand)\
**Post date:** [January 14, 2024, 11:59am UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/12 "2024-01-14T11:59:09Z")

</div>

> But I define on `meta/main.yml` as **python\_developer**. But it is being imported as **python-developer**. This is completely counter-intuitive, I am against having to add additional parameter on the CLI since it is already specified on metadata.

I agree with @staticdev here. I’ve also just experienced the same problem. My role’s [`meta/main.yml`](https://github.com/dbrennand/ansible-role-caddy-docker/blob/main/meta/main.yml#L2) with:

```auto
galaxy_info:
  role_name: caddy_docker
  ...

```

Ended up being imported as `caddy-docker`, which caused quite some confusion for me 😅. It does seem a bit counter-intuitive to specify `--role-name` on the CLI when the details are already defined in `meta/main.yml` 🙁

---

<div class="post-metadata">

**Author:** ![dbrennand](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dbrennand/32/7830_2.png) [@dbrennand](https://forum.ansible.com/u/dbrennand)\
**Post date:** [January 18, 2024, 5:34pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/13 "2024-01-18T17:34:33Z")

</div>

For those using GitHub Actions, I’m using the following [workaround](http://forum.ansible.com/t/galaxy-import-successful-but-latest-versions-error-to-download/3231/7). Posting here in case this helps anyone else who experiences a similar issue. 🙂

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [January 19, 2024, 1:42pm UTC](https://forum.ansible.com/t/ansible-galaxy-s-role-import-enhancements-and-fixes-for-the-new-year/3206/14 "2024-01-19T13:42:03Z")

</div>

Backports have been merged for [[ansible-galaxy] Remove role name conversion when the repo startswith 'ansible-role' by s-hertel · Pull Request #82508 · ansible/ansible · GitHub](https://github.com/ansible/ansible/pull/82508), so the issue with repositories that start with the prefix `ansible-role` will be fixed in 2.15.9 and 2.16.3 (rc1 scheduled for Jan 22, GA on Jan 29). The ansible-role-name → name conversion has been removed, and the galaxy\_info `role_name` or the `--role-name` option can override the repository as the role name. The only workaround for older versions of anible-core is to use the `--role-name` option.
