From da3a7618baa500899d11bb9a80863fdb1f80e3f1 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:00:56 -0400 Subject: [PATCH] give a warning when no roles match the search instead of returning rc 1 (#79195) * give a warning when no roles match the search instead of returning rc 1 * porting guide note * Update docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst Co-authored-by: Sviatoslav Sydorenko --- changelogs/fragments/ansible-galaxy-role-search-rc.yml | 4 ++++ docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst | 2 +- lib/ansible/cli/galaxy.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/ansible-galaxy-role-search-rc.yml diff --git a/changelogs/fragments/ansible-galaxy-role-search-rc.yml b/changelogs/fragments/ansible-galaxy-role-search-rc.yml new file mode 100644 index 00000000000..a104f94865e --- /dev/null +++ b/changelogs/fragments/ansible-galaxy-role-search-rc.yml @@ -0,0 +1,4 @@ +bugfixes: + - >- + ``ansible-galaxy search rolename`` - give a warning instead of non-zero return code when search results are empty. + This is similar to the behavior when listing roles, which gives a warning if a role cannot be found and exits with a return code of ``0``. diff --git a/docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst b/docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst index 782288c1d1d..8b4478cd1e4 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst @@ -25,7 +25,7 @@ No notable changes Command Line ============ -No notable changes +* The return code of ``ansible-galaxy search`` is now 0 instead of 1 and the stdout is empty when results are empty to align with other ``ansible-galaxy`` commands. Deprecated diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index f4148d924db..339094e035a 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -1721,8 +1721,8 @@ class GalaxyCLI(CLI): tags=context.CLIARGS['galaxy_tags'], author=context.CLIARGS['author'], page_size=page_size) if response['count'] == 0: - display.display("No roles match your search.", color=C.COLOR_ERROR) - return 1 + display.warning("No roles match your search.") + return 0 data = [u'']