From 13dec9259fcee42d3765fba763f087fc827d2677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Mon, 14 Aug 2017 23:17:22 +0200 Subject: [PATCH] galaxy-cli: selective install roles in requirements file (#21412) * galaxy-cli: force install selected roles in requirements file * only when requirements file but also handle uninstalled roles --- lib/ansible/cli/galaxy.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 4bcea4f7f1e..768433b7f8c 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -311,9 +311,6 @@ class GalaxyCLI(CLI): if len(self.args) == 0 and role_file is None: # the user needs to specify one of either --role-file or specify a single user/role name raise AnsibleOptionsError("- you must specify a user/role name or a roles file") - elif len(self.args) == 1 and role_file is not None: - # using a role file is mutually exclusive of specifying the role name on the command line - raise AnsibleOptionsError("- please specify a user/role name, or a roles file, but not both") no_deps = self.options.no_deps force = self.options.force @@ -368,11 +365,17 @@ class GalaxyCLI(CLI): roles_left.append(GalaxyRole(self.galaxy, **role)) for role in roles_left: - display.vvv('Installing role %s ' % role.name) + # only process roles in roles files when names matches if given + if role_file and self.args and role.name not in self.args: + display.vvv('Skipping role %s' % role.name) + continue + + display.vvv('Processing role %s ' % role.name) + # query the galaxy API for the role data if role.install_info is not None: - if role.install_info['version'] != role.version: + if role.install_info['version'] != role.version or force: if force: display.display('- changing role %s from %s to %s' % (role.name, role.install_info['version'], role.version or "unspecified"))