Skip to content

Commit

Permalink
Fix the homebrew module failing because of warnings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Strahinja Kustudic committed May 22, 2024
1 parent 4792e21 commit 0abb8c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8406-fix-homebrew-cask-warning.yaml
Original file line number Diff line number Diff line change
@@ -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).
4 changes: 2 additions & 2 deletions plugins/modules/homebrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ def _current_package_is_installed(self):
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)

Expand Down
14 changes: 0 additions & 14 deletions tests/integration/targets/homebrew/tasks/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0abb8c6

Please sign in to comment.