New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure roles have a namespace when created #3277
Conversation
47e4a83
to
01a443a
Compare
As test tools require the presence of a namespace, we now detect when user is trying to create standalone roles and require him to mention the namespace. Related: ansible/ansible-compat#78
01a443a
to
a070742
Compare
|
||
# outside collections our tooling needs a namespace. | ||
if not os.path.isfile("../galaxy.yml"): | ||
name_re = re.compile(r"^[a-z][a-z0-9_]+\.[a-z][a-z0-9_]+$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you have this regex here already, why not declare groups for the namespace and the role and just extract them from match()
instead of re-splitting later?
if not os.path.isfile("../galaxy.yml"): | ||
name_re = re.compile(r"^[a-z][a-z0-9_]+\.[a-z][a-z0-9_]+$") | ||
|
||
if not name_re.match(role_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, note the ansible-core has a more precise check that you may want to reuse: https://github.com/ansible/ansible/pull/73279/files#diff-3d1b69b541811ef19d2c1ede9acd53ed73c6cafe37b787c3ce209357279c6c01R871-R876. It doesn't use regex directly but a check for something being a valid Python identifier.
Plus, we could just reuse that method. It exists since ansible v2.9.
if not name_re.match(role_name): | |
from ansible.utils.collection_loader import AnsibleCollectionRef | |
if not AnsibleCollectionRef.is_valid_fqcr(role_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge that like this because fixing that bug is quite important. My plan was to add code to ansible-compat for doing this but that may take extra time. I will look into replacing this code with the one from compat, once we have it.
Note: I plan to address this in follow-up. |
As test tools require the presence of a namespace, we now detect when user is trying to create standalone roles and require him to mention the namespace.
This also updates the command line help text to provide better information regarding what is expected from the user.
This change does not affect creation of new roles within collections.
Related: ansible/ansible-compat#78