# Regex bug in galaxy-importer

**URL:** <https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431>\
**Category:** Get Help\
**Tags:** galaxy-ng\
**Created:** [October 2, 2023, 8:29am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431 "2023-10-02T08:29:50Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodsch](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bodsch/32/906_2.png) [@bodsch](https://forum.ansible.com/u/bodsch)\
**Post date:** [October 2, 2023, 8:29am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/1 "2023-10-02T08:29:50Z")

</div>

I have a similar problem to [Unable to manage roles in the new Galaxy-ng portal?](http://forum.ansible.com/t/unable-to-manage-roles-in-the-new-galaxy-ng-portal/1214)  
The import via the CLI does not work:

```auto
ansible-galaxy import --token=$(cat ~/.ansible_galaxy_token) bodsch ansible-glauth --role-name glauth --verbose --branch=1.4.1
Using /home/bodsch/.ansible.cfg as config file
Successfully submitted import request ...
unknown field in galaxy_info
  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 127, in legacy_role_import
    result = import_legacy_role(checkout_path, namespace.name, importer_config, logger)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/legacy_role.py", line 51, in import_legacy_role
    return _import_legacy_role(dirname, namespace, cfg, logger)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/legacy_role.py", line 57, in _import_legacy_role
    data = LegacyRoleLoader(dirname, namespace, cfg, logger).load()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/loaders/legacy_role.py", line 41, in load
    self.metadata = self._load_metadata()
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/loaders/legacy_role.py", line 77, in _load_metadata
    return schema.LegacyMetadata.parse(meta_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/schema.py", line 522, in parse
    raise exc.LegacyRoleSchemaError("unknown field in galaxy_info") from e

```

But it looks like a server-side problem to me.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [October 2, 2023, 8:31am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/2 "2023-10-02T08:31:56Z")

</div>

Does `ansible-lint` have any warnings on the Galaxy metadata for the role?

---

<div class="post-metadata">

**Author:** ![bodsch](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bodsch/32/906_2.png) [@bodsch](https://forum.ansible.com/u/bodsch)\
**Post date:** [October 2, 2023, 8:44am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/3 "2023-10-02T08:44:32Z")

</div>

`ansible-lint` does not find any errors.

```auto
ansible-lint .

Passed: 0 failure(s), 0 warning(s) on 24 files. Last profile that met the validation criteria was 'production'.

```

The lint config is simple:

```auto
cat .ansible-lint 
---

skip_list:
  - name[casing]
  - name[template]

```

The import has also worked without any problems so far.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [October 2, 2023, 7:37pm UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/4 "2023-10-02T19:37:49Z")

</div>

Comparing the schema in galaxy-importer ([https://github.com/ansible/galaxy-importer/blob/master/galaxy\_importer/schema.py#L387-L400](https://github.com/ansible/galaxy-importer/blob/master/galaxy_importer/schema.py#L387-L400)) with your `galaxy_info` ([https://github.com/bodsch/ansible-glauth/blob/main/meta/main.yml](https://github.com/bodsch/ansible-glauth/blob/main/meta/main.yml)), it looks like the offender is the `namespace` field.

That field was apparently introduced by ansible-lint, but it could be that galaxy-importer got stricter some time ago (the old community Galaxy used an older version of it) and this now clashes with that field. CC @ssbarnea.

---

<div class="post-metadata">

**Author:** ![bodsch](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bodsch/32/906_2.png) [@bodsch](https://forum.ansible.com/u/bodsch)\
**Post date:** [October 3, 2023, 3:36pm UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/5 "2023-10-03T15:36:56Z")

</div>

I couldn’t import Ansible roles without this field for a long time.

In the [workflow history](https://github.com/bodsch/ansible-glauth/actions/workflows/galaxy.yml) you can also see that the automatic import always worked, until the current update of the Galaxy.

**It would be massively helpful to upgrade the import error message accordingly!**

With an “unknown field in galaxy\_info” you are pretty helpless.

And unfortunately `namespace` is **not** the cause! ☹

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 3, 2023, 4:50pm UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/6 "2023-10-03T16:50:14Z")

</div>

I’m wondering if the “`-`” in `https://github.com/bodsch/ansible-glauth/` is messing you up.

In the [galaxy-importer](https://github.com/ansible/galaxy-importer/), `galaxy-importer/constants.py` line 61, there’s a broken regex introduced about 3 months ago:

```py
# Matches role names with any combination of lowercase letters,
# uppercase letters, numbers, underscores, and hyphens with
# a length in the inclusive range [1, 55].
LEGACY_ROLE_NAME_REGEXP = re.compile("^[a-zA-Z0-9-_]{1,55}$")

```

It’s supposed to accept underscores and hyphens, but it doesn’t. Rather it accepts `'9' through '_'`. It should be

```py
LEGACY_ROLE_NAME_REGEXP = re.compile("^[a-zA-Z0-9_-]{1,55}$")

```

---

<div class="post-metadata">

**Author:** ![bodsch](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bodsch/32/906_2.png) [@bodsch](https://forum.ansible.com/u/bodsch)\
**Post date:** [October 5, 2023, 4:26am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/8 "2023-10-05T04:26:47Z")

</div>

Sleep on it once and more coffee and I understand my problem.

I guess I need to fix all my roles.

---

<div class="post-metadata">

**Author:** ![gwmngilfen](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gwmngilfen/32/6_2.png) [@gwmngilfen](https://forum.ansible.com/u/gwmngilfen)\
**Post date:** [October 5, 2023, 10:01am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/9 "2023-10-05T10:01:40Z")

</div>

@utoddl does it make sense to move this point about regexes to a new topic? The original request is solved but I think you might have something worth discussing there…

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 5, 2023, 10:31am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/10 "2023-10-05T10:31:23Z")

</div>

Makes sense to me, moving this regex issue to a new topic. That has to be done by a moderator I suppose? I don’t see a way to do it myself.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 5, 2023, 10:38am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/11 "2023-10-05T10:38:53Z")

</div>

Note: this is being worked on:

> [a17f996](https://github.com/ansible/galaxy-importer/commit/a17f996f8a8d513c52e7a545632ac6db4fdd8474) Change regexp for legacy role name to correcly match underscore or hyphen

---

<div class="post-metadata">

**Author:** ![gwmngilfen](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gwmngilfen/32/6_2.png) [@gwmngilfen](https://forum.ansible.com/u/gwmngilfen)\
**Post date:** [October 5, 2023, 10:46am UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/12 "2023-10-05T10:46:54Z")

</div>

Yes, it’s a moderator action. Once the forum has settled in I hope to promote some additional moderators 😉

I’ve moved the posts, but it sounds like it’s already in hand. Is there also a case for that error message to improve?

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 5, 2023, 5:43pm UTC](https://forum.ansible.com/t/regex-bug-in-galaxy-importer/1431/13 "2023-10-05T17:43:56Z")

</div>

> [@gwmngilfen](#):
>
> Is there also a case for that error message to improve?

Hard to say. I was searching “upstream” from the “unknown field” message trying to ferret out what field could be the issue, and frankly I didn’t see justification for that wording. Emphasis on “didn’t see” — it could be spot on, but I’d never looked at that code before and wouldn’t bet dessert on what it’s actually doing. When I spotted that regex issue I quit looking.
