From b6f38951de93de8da751692d77eae1b36aee8267 Mon Sep 17 00:00:00 2001 From: s-hertel <19572925+s-hertel@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:08:25 -0400 Subject: [PATCH] Add a --namespace option to ansible-galaxy role import --- .../fragments/ansible-galaxy-role-import-namespace.yml | 5 +++++ lib/ansible/cli/galaxy.py | 5 ++++- lib/ansible/galaxy/api.py | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/ansible-galaxy-role-import-namespace.yml diff --git a/changelogs/fragments/ansible-galaxy-role-import-namespace.yml b/changelogs/fragments/ansible-galaxy-role-import-namespace.yml new file mode 100644 index 00000000000..df2a6b9df09 --- /dev/null +++ b/changelogs/fragments/ansible-galaxy-role-import-namespace.yml @@ -0,0 +1,5 @@ +minor_changes: +- >- + ``ansible-galaxy role import`` - add ``--namespace`` to publish the role to + a namespace other than the Github user. This option takes precedence over the + ``namespace`` field in the ``galaxy_info`` field of the ``meta/main.yml``. diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 805bd650372..8d9b181aa77 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -419,6 +419,8 @@ class GalaxyCLI(CLI): '(usually master)') import_parser.add_argument('--role-name', dest='role_name', help='The name the role should have, if different than the repo name') + import_parser.add_argument('--namespace', dest='role_namespace', + help='The role namespace, if different than the user name') import_parser.add_argument('--status', dest='check_status', action='store_true', default=False, help='Check the status of the most recent import request for given github_' 'user/github_repo.') @@ -1805,7 +1807,8 @@ class GalaxyCLI(CLI): # Submit an import request task = self.api.create_import_task(github_user, github_repo, reference=context.CLIARGS['reference'], - role_name=context.CLIARGS['role_name']) + role_name=context.CLIARGS['role_name'], + namespace=context.CLIARGS['role_namespace']) if len(task) > 1: # found multiple roles associated with github_user/github_repo diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py index 156dd4cf700..4323f07fa8e 100644 --- a/lib/ansible/galaxy/api.py +++ b/lib/ansible/galaxy/api.py @@ -479,7 +479,7 @@ class GalaxyAPI: return data @g_connect(['v1']) - def create_import_task(self, github_user, github_repo, reference=None, role_name=None): + def create_import_task(self, github_user, github_repo, reference=None, role_name=None, namespace=None): """ Post an import request """ @@ -491,6 +491,8 @@ class GalaxyAPI: } if role_name: args['alternate_role_name'] = role_name + if namespace: + args['alternate_namespace_name'] = namespace data = self._call_galaxy(url, args=urlencode(args), method="POST") if data.get('results', None): return data['results']