Skip to content

Commit 56eb5b3

Browse files
authored
Allow user to specify namespace for standalone roles (#1451)
This change allows user to specify the desired namespace under which the role is expected to be published. This allows us to better test the role as it was installed, including performing syntax check on test playbooks. Previous implementation was forcing user to convert its author field to a namespace compatible string. We no longer need this as galaxy-importer does not have any problem when it encounters unknown fields. Namespace is also used in collections, so it would be easier for to remember for users.
1 parent c9f27fa commit 56eb5b3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/ansiblelint/_prerun.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ def _install_galaxy_role() -> None:
154154
if 'galaxy_info' not in yaml:
155155
return
156156
role_name = yaml['galaxy_info'].get('role_name', None)
157-
role_author = yaml['galaxy_info'].get('author', None)
157+
role_namespace = yaml['galaxy_info'].get('namespace', None)
158+
if not role_namespace:
159+
role_namespace = yaml['galaxy_info'].get('author', None)
158160
if not role_name:
159161
role_name = pathlib.Path(".").absolute().name
160162
role_name = re.sub(r'^{0}'.format(re.escape('ansible-role-')), '', role_name)
161-
fqrn = f"{role_author}.{role_name}"
163+
fqrn = f"{role_namespace}.{role_name}"
162164
if not re.match(r"[a-z0-9][a-z0-9_]+\.[a-z][a-z0-9_]+$", fqrn):
163165
print(
164166
f"""\
@@ -167,7 +169,7 @@ def _install_galaxy_role() -> None:
167169
168170
galaxy_info:
169171
role_name: my_name # if absent directory name hosting role is used instead
170-
author: my_galaxy_namespace
172+
namespace: my_galaxy_namespace # if absent, author is used instead
171173
172174
Namespace: https://galaxy.ansible.com/docs/contributing/namespaces.html#galaxy-namespace-limitations
173175
Role: https://galaxy.ansible.com/docs/contributing/creating_role.html#role-names
@@ -177,7 +179,7 @@ def _install_galaxy_role() -> None:
177179
sys.exit(INVALID_PREREQUISITES_RC)
178180
p = pathlib.Path(f"{options.project_dir}/.cache/roles")
179181
p.mkdir(parents=True, exist_ok=True)
180-
link_path = p / f"{role_author}.{role_name}"
182+
link_path = p / f"{role_namespace}.{role_name}"
181183
# despite documentation stating that is_file() reports true for symlinks,
182184
# it appears that is_dir() reports true instead, so we rely on exits().
183185
if not link_path.exists():

0 commit comments

Comments
 (0)