diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 00efa1e81c..ddeb67fd3b 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -80,6 +80,7 @@ class GalaxyCLI(CLI): self.parser.set_usage("usage: %prog import [options] github_user github_repo") self.parser.add_option('--no-wait', dest='wait', action='store_false', default=True, help='Don\'t wait for import results.') self.parser.add_option('--branch', dest='reference', help='The name of a branch to import. Defaults to the repository\'s default branch (usually master)') + self.parser.add_option('--role-name', dest='role_name', help='The name the role should have, if different than the repo name') self.parser.add_option('--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.') elif self.action == "info": self.parser.set_usage("usage: %prog info [options] role_name[,version]") @@ -567,7 +568,7 @@ class GalaxyCLI(CLI): task = self.api.get_import_task(github_user=github_user, github_repo=github_repo) else: # Submit an import request - task = self.api.create_import_task(github_user, github_repo, reference=self.options.reference) + task = self.api.create_import_task(github_user, github_repo, reference=self.options.reference, role_name=self.options.role_name) 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 64fb82575b..c3df49ddc0 100644 --- a/lib/ansible/galaxy/api.py +++ b/lib/ansible/galaxy/api.py @@ -140,17 +140,21 @@ class GalaxyAPI(object): return data @g_connect - def create_import_task(self, github_user, github_repo, reference=None): + def create_import_task(self, github_user, github_repo, reference=None, role_name=None): """ Post an import request """ url = '%s/imports/' % self.baseurl - args = urlencode({ + args = { "github_user": github_user, "github_repo": github_repo, "github_reference": reference if reference else "" - }) - data = self.__call_galaxy(url, args=args) + } + if role_name: + args['alternate_role_name'] = role_name + elif github_repo.startswith('ansible-role'): + args['alternate_role_name'] = github_repo[len('ansible-role')+1:] + data = self.__call_galaxy(url, args=urlencode(args)) if data.get('results', None): return data['results'] return data