From 42a13d15f1587174d165912cc5b096cf34cafbcb Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 10 Dec 2018 11:41:22 -0500 Subject: [PATCH] add path info to role list (#49346) * add path info to role list - use same display format for both listing all and specific roles Co-Authored-By: bcoca --- changelogs/fragments/nicer_role_list.yml | 2 ++ lib/ansible/cli/galaxy.py | 37 ++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 changelogs/fragments/nicer_role_list.yml diff --git a/changelogs/fragments/nicer_role_list.yml b/changelogs/fragments/nicer_role_list.yml new file mode 100644 index 00000000000..59d508d2e52 --- /dev/null +++ b/changelogs/fragments/nicer_role_list.yml @@ -0,0 +1,2 @@ +minor_changes: + - now galaxy shows each path where it finds roles when listing them diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index daaad4df89e..54843888e97 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -460,45 +460,46 @@ class GalaxyCLI(CLI): if len(self.args) > 1: raise AnsibleOptionsError("- please specify only one role to list, or specify no roles to see a full list") + def _display_role(gr): + install_info = gr.install_info + version = None + if install_info: + version = install_info.get("version", None) + if not version: + version = "(unknown version)" + display.display("- %s, %s" % (gr.name, version)) + if len(self.args) == 1: - # show only the request role, if it exists + # show the requested role, if it exists name = self.args.pop() gr = GalaxyRole(self.galaxy, name) if gr.metadata: - install_info = gr.install_info - version = None - if install_info: - version = install_info.get("version", None) - if not version: - version = "(unknown version)" - # show some more info about single roles here - display.display("- %s, %s" % (name, version)) + display.display('# %s' % os.path.dirname(gr.path)) + _display_role(gr) else: display.display("- the role %s was not found" % name) else: # show all valid roles in the roles_path directory roles_path = self.options.roles_path path_found = False + warnings = [] for path in roles_path: role_path = os.path.expanduser(path) if not os.path.exists(role_path): - display.warning("- the configured path %s does not exist." % role_path) + warnings.append("- the configured path %s does not exist." % role_path) continue elif not os.path.isdir(role_path): - display.warning("- the configured path %s, exists, but it is not a directory." % role_path) + warnings.append("- the configured path %s, exists, but it is not a directory." % role_path) continue + display.display('# %s' % role_path) path_files = os.listdir(role_path) path_found = True for path_file in path_files: gr = GalaxyRole(self.galaxy, path_file, path=path) if gr.metadata: - install_info = gr.install_info - version = None - if install_info: - version = install_info.get("version", None) - if not version: - version = "(unknown version)" - display.display("- %s, %s" % (path_file, version)) + _display_role(gr) + for w in warnings: + display.warning(w) if not path_found: raise AnsibleOptionsError("- None of the provided paths was usable. Please specify a valid path with --roles-path") return 0