From f0db1d1f6b3e1d79bdb03fa6c58476e09248db67 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 26 May 2024 21:17:46 +0200 Subject: [PATCH] [PR #8406/43cb5a0d backport][stable-9] Fix the homebrew module failing because of warnings (#8425) Fix the homebrew module failing because of warnings (#8406) Instead of checking if there is an error message, which can also be a warning, we now check the return code. This commit fixes #8229 #7044 Co-authored-by: Strahinja Kustudic (cherry picked from commit 43cb5a0d54856f1f09026e476a5b8ee03b44cf0b) Co-authored-by: Strahinja Kustudic --- .../fragments/8406-fix-homebrew-cask-warning.yaml | 2 ++ plugins/modules/homebrew.py | 4 ++-- .../integration/targets/homebrew/tasks/docker.yml | 14 -------------- 3 files changed, 4 insertions(+), 16 deletions(-) create mode 100644 changelogs/fragments/8406-fix-homebrew-cask-warning.yaml diff --git a/changelogs/fragments/8406-fix-homebrew-cask-warning.yaml b/changelogs/fragments/8406-fix-homebrew-cask-warning.yaml new file mode 100644 index 0000000000..0e3bf38ed3 --- /dev/null +++ b/changelogs/fragments/8406-fix-homebrew-cask-warning.yaml @@ -0,0 +1,2 @@ +bugfixes: + - homebrew - do not fail when brew prints warnings (https://github.com/ansible-collections/community.general/pull/8406, https://github.com/ansible-collections/community.general/issues/7044). diff --git a/plugins/modules/homebrew.py b/plugins/modules/homebrew.py index 388682d924..2b60846b43 100644 --- a/plugins/modules/homebrew.py +++ b/plugins/modules/homebrew.py @@ -415,9 +415,9 @@ class Homebrew(object): if self.force_formula: cmd.append("--formula") rc, out, err = self.module.run_command(cmd) - if err: + if rc != 0: self.failed = True - self.message = err.strip() + self.message = err.strip() or ("Unknown failure with exit code %d" % rc) raise HomebrewException(self.message) data = json.loads(out) diff --git a/tests/integration/targets/homebrew/tasks/docker.yml b/tests/integration/targets/homebrew/tasks/docker.yml index 3b9e2ea6b4..c7f282ba2d 100644 --- a/tests/integration/targets/homebrew/tasks/docker.yml +++ b/tests/integration/targets/homebrew/tasks/docker.yml @@ -12,20 +12,6 @@ path: "{{ brew_which.stdout }}" register: brew_stat -- name: MACOS | Install docker without --formula - community.general.homebrew: - name: docker - state: present - become: true - become_user: "{{ brew_stat.stat.pw_name }}" - ignore_errors: true - register: result - -- name: Check that installing docker without --formula raises warning - assert: - that: - - result is failed - - name: MACOS | Install docker community.general.homebrew: name: docker