Repository: ansible-collections/community.general

Issue:
homebrew: reports failure when installing "emacs" formula
### Summary

When I try to install the "emacs" formula I get this error:
```
Warning: Treating emacs as a formula. For the cask, use homebrew/cask/emacs or specify the `--cask` flag.
```

### Issue Type

Bug Report

### Component Name

homebrew

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.16.5]
  config file = None
  configured module search path = ['/Users/mark/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/9.4.0_1/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/mark/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] (/opt/homebrew/Cellar/ansible/9.4.0_1/libexec/bin/python)
  jinja version = 3.1.3
  libyaml = True
```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general
# /opt/homebrew/Cellar/ansible/9.4.0_1/libexec/lib/python3.12/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 8.5.0  
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /Users/mark/bin/scripts/emacs
PAGER(env: PAGER) = less
```


### OS / Environment

macOS 14.4.1 (23E224) on Apple Silicon M1
Homebrew 4.2.18


### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- name: "homebrew : install emacs"
  homebrew:
    name:
      - emacs
  become: true
  become_user: mark
```


### Expected Results

I expect to install the "emacs" formula without issuing an error.

### Actual Results

```console (paste below)
$ ansible-playbook -i inventory/main.yml site.yml -t macos --limit macbook-2020-wireless.ddf.intranet -vvv
ansible-playbook [core 2.16.5]
  config file = None
  configured module search path = ['/Users/mark/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/9.4.0_1/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/mark/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-playbook
  python version = 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] (/opt/homebrew/Cellar/ansible/9.4.0_1/libexec/bin/python)
  jinja version = 3.1.3
  libyaml = True
No config file found; using defaults
host_list declined parsing /Users/mark/code/ddf-ansible/inventory/main.yml as it did not pass its verify_file() method
script declined parsing /Users/mark/code/ddf-ansible/inventory/main.yml as it did not pass its verify_file() method
Parsed /Users/mark/code/ddf-ansible/inventory/main.yml inventory source with yaml plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: site.yml *************************************************************
10 plays in site.yml

PLAY [base Debian configuration] ***********************************************

PLAY [base macOS configuration] ************************************************

TASK [macos-base : include_tasks] **********************************************
task path: /Users/mark/code/ddf-ansible/roles/macos-base/tasks/main.yml:2
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
included: /Users/mark/code/ddf-ansible/roles/macos-base/tasks/homebrew.yml for macbook-2020-wireless.ddf.intranet

TASK [macos-base : homebrew : install emacs] ***********************************
task path: /Users/mark/code/ddf-ansible/roles/macos-base/tasks/homebrew.yml:2
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
<macbook-2020-wireless.ddf.intranet> ESTABLISH SSH CONNECTION FOR USER: root
<macbook-2020-wireless.ddf.intranet> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' macbook-2020-wireless.ddf.intranet '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<macbook-2020-wireless.ddf.intranet> (0, b'/var/root\n', b'')
<macbook-2020-wireless.ddf.intranet> ESTABLISH SSH CONNECTION FOR USER: root
<macbook-2020-wireless.ddf.intranet> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' macbook-2020-wireless.ddf.intranet '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /var/tmp `"&& mkdir "` echo /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086 `" && echo ansible-tmp-1713349079.605263-26016-197675568165086="` echo /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086 `" ) && sleep 0'"'"''
<macbook-2020-wireless.ddf.intranet> (0, b'ansible-tmp-1713349079.605263-26016-197675568165086=/var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086\n', b'')
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
<macbook-2020-wireless.ddf.intranet> Attempting python interpreter discovery
<macbook-2020-wireless.ddf.intranet> ESTABLISH SSH CONNECTION FOR USER: root
<macbook-2020-wireless.ddf.intranet> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' macbook-2020-wireless.ddf.intranet '/bin/sh -c '"'"'echo PLATFORM; uname; echo FOUND; command -v '"'"'"'"'"'"'"'"'python3.12'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.11'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.10'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.9'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.8'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python3'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/libexec/platform-python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python'"'"'"'"'"'"'"'"'; echo ENDFOUND && sleep 0'"'"''
<macbook-2020-wireless.ddf.intranet> (0, b'PLATFORM\nDarwin\nFOUND\n/usr/bin/python3\nENDFOUND\n', b'')
<macbook-2020-wireless.ddf.intranet> Python interpreter discovery fallback (unsupported platform for extended discovery: darwin)
Using module file /opt/homebrew/Cellar/ansible/9.4.0_1/libexec/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/homebrew.py
<macbook-2020-wireless.ddf.intranet> PUT /Users/mark/.ansible/tmp/ansible-local-26012cb3gygb4/tmp8qfs6gfn TO /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/AnsiballZ_homebrew.py
<macbook-2020-wireless.ddf.intranet> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' '[macbook-2020-wireless.ddf.intranet]'
<macbook-2020-wireless.ddf.intranet> (0, b'sftp> put /Users/mark/.ansible/tmp/ansible-local-26012cb3gygb4/tmp8qfs6gfn /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/AnsiballZ_homebrew.py\n', b'')
<macbook-2020-wireless.ddf.intranet> ESTABLISH SSH CONNECTION FOR USER: root
<macbook-2020-wireless.ddf.intranet> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' macbook-2020-wireless.ddf.intranet '/bin/sh -c '"'"'setfacl -m u:mark:r-x /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/ /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/AnsiballZ_homebrew.py && sleep 0'"'"''
<macbook-2020-wireless.ddf.intranet> (127, b'', b'/bin/sh: setfacl: command not found\n')
<macbook-2020-wireless.ddf.intranet> Failed to connect to the host via ssh: /bin/sh: setfacl: command not found
<macbook-2020-wireless.ddf.intranet> ESTABLISH SSH CONNECTION FOR USER: root
<macbook-2020-wireless.ddf.intranet> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' macbook-2020-wireless.ddf.intranet '/bin/sh -c '"'"'chmod u+x /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/ /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/AnsiballZ_homebrew.py && sleep 0'"'"''
<macbook-2020-wireless.ddf.intranet> (0, b'', b'')
<macbook-2020-wireless.ddf.intranet> ESTABLISH SSH CONNECTION FOR USER: root
<macbook-2020-wireless.ddf.intranet> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' macbook-2020-wireless.ddf.intranet '/bin/sh -c '"'"'chown mark /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/ /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/AnsiballZ_homebrew.py && sleep 0'"'"''
<macbook-2020-wireless.ddf.intranet> (0, b'', b'')
<macbook-2020-wireless.ddf.intranet> ESTABLISH SSH CONNECTION FOR USER: root
<macbook-2020-wireless.ddf.intranet> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' -tt macbook-2020-wireless.ddf.intranet '/bin/sh -c '"'"'sudo -H -S -n  -u mark /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-jxffvulggznewlinyqnxidvwxiqiwxab ; /usr/bin/python3 /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/AnsiballZ_homebrew.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<macbook-2020-wireless.ddf.intranet> (1, b'shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied\r\njob-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied\r\n\r\n{"failed": true, "msg": "Warning: Treating emacs as a formula. For the cask, use homebrew/cask/emacs or specify the `--cask` flag.", "invocation": {"module_args": {"name": ["emacs"], "path": "/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin", "state": "present", "update_homebrew": false, "upgrade_all": false, "install_options": [], "upgrade_options": []}}}\r\n', b'Shared connection to macbook-2020-wireless.ddf.intranet closed.\r\n')
<macbook-2020-wireless.ddf.intranet> Failed to connect to the host via ssh: Shared connection to macbook-2020-wireless.ddf.intranet closed.
<macbook-2020-wireless.ddf.intranet> ESTABLISH SSH CONNECTION FOR USER: root
<macbook-2020-wireless.ddf.intranet> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/Users/mark/.ansible/cp/0622c77de3"' macbook-2020-wireless.ddf.intranet '/bin/sh -c '"'"'rm -f -r /var/tmp/ansible-tmp-1713349079.605263-26016-197675568165086/ > /dev/null 2>&1 && sleep 0'"'"''
<macbook-2020-wireless.ddf.intranet> (0, b'', b'')
fatal: [macbook-2020-wireless.ddf.intranet]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "install_options": [],
            "name": [
                "emacs"
            ],
            "path": "/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin",
            "state": "present",
            "update_homebrew": false,
            "upgrade_all": false,
            "upgrade_options": []
        }
    },
    "msg": "Warning: Treating emacs as a formula. For the cask, use homebrew/cask/emacs or specify the `--cask` flag."
}

PLAY RECAP *********************************************************************
macbook-2020-wireless.ddf.intranet : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
homebrew module: task fails on warning message
### Summary

Given this Ansible task:

```
- community.general.homebrew:
        name:
          - android-studio
          - clion
          - cyberduck
          - intellij-idea-ce
          - keka
          - vscodium
        state: latest
```

If one of the packages is already the latest version, execution is stopped and the tasks fails:
```
fatal: [host.example.org]: FAILED! => changed=false 
  msg: 'Warning: Not upgrading android-studio, the latest version is already installed'
```

I expect this to be a non-fatal warning, and that it continues running the playbook.

### Issue Type

Bug Report

### Component Name

homebrew

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.14.3]
  config file = /home/frederik/ig-macos/ansible.cfg
  configured module search path = ['/home/frederik/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/frederik/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general

# /home/frederik/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 3.6.0  

# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 6.4.0  

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
ANSIBLE_NOCOWS(/home/frederik/ig-macos/ansible.cfg) = True
CONFIG_FILE() = /home/frederik/ig-macos/ansible.cfg
DEFAULT_FORKS(/home/frederik/ig-macos/ansible.cfg) = 16
DEFAULT_HOST_LIST(/home/frederik/ig-macos/ansible.cfg) = ['/home/frederik/ig-macos/inventory']
DEFAULT_LOG_PATH(/home/frederik/ig-macos/ansible.cfg) = /home/frederik/ig-macos/ansible.log
DEFAULT_ROLES_PATH(/home/frederik/ig-macos/ansible.cfg) = ['/home/frederik/ig-macos/roles', '/etc/ansible/roles']
DEFAULT_STDOUT_CALLBACK(/home/frederik/ig-macos/ansible.cfg) = yaml
DEFAULT_STRATEGY(/home/frederik/ig-macos/ansible.cfg) = free
DEFAULT_TIMEOUT(/home/frederik/ig-macos/ansible.cfg) = 60

```


### OS / Environment

Debian 12

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- community.general.homebrew:
        name:
          - android-studio
          - clion
          - cyberduck
          - intellij-idea-ce
          - keka
          - vscodium
        state: latest
```


### Expected Results

When one of the packages is already up to date, it continues upgrading the other packages and this tasks succeeds.

### Actual Results

```console (paste below)
fatal: [host.example.org]: FAILED! => changed=false 
  msg: 'Warning: Not upgrading android-studio, the latest version is already installed'
```

Execution stops at this point.

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
When I run brew directly I get this:
```console
$ brew install emacs
Warning: Treating emacs as a formula. For the cask, use homebrew/cask/emacs or specify the `--cask` flag.
Warning: emacs 29.3 is already installed and up-to-date.
To reinstall 29.3, run:
  brew reinstall emacs
```
Adding the `--formulae` option suppresses the warning message that's triggering the error in Ansible:
```console
$ brew install --formulae emacs
==> Downloading https://formulae.brew.sh/api/formula.jws.json

Warning: emacs 29.3 is already installed and up-to-date.
To reinstall 29.3, run:
  brew reinstall emacs
```
cc @Akasurde @danieljaouen @indrajitr @kyleabenson @martinm82
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
See also #7044.
!component =plugins/modules/homebrew.py
cc @andrew-d
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Same issue discussed here as well:
https://github.com/ansible-collections/community.general/issues/8274
Files identified in the description:
* [`plugins/callback/say.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/callback/say.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Akasurde @danieljaouen @indrajitr @kyleabenson @martinm82
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
!component =plugins/modules/homebrew.py
Files identified in the description:
* [`plugins/modules/homebrew.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/homebrew.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @andrew-d
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I was just having the same issue with `visual-studio-code`. It was fixed by using the `community.general.homebrew_cask` module instead, which should apply here too, since `android-studio` is a Cask, not a Formula.
Is this fixed or any other workarounds? I am having the same issue with `community.general.homebrew_cask` with Temurin8 installation(or skip if exists) still in 2024 Feb

Avoiding with `$HOMEBREW_PATH/Caskroom` check as workaround.
We see a similar failure mode when the intention _is_ to install a formula.

> failed: [localhost] (item=docker) => {"ansible_loop_var": "item", "changed": false, "item": "docker", "msg": "Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker or specify the `--cask` flag."}

What's the recommended approach here?
@HarryWeppner seeing the same issue. Tried adding `install_options: formula` and it didn't help. `ignore_errors: true` works but is... not ideal
> We see a similar failure mode when the intention _is_ to install a formula.
> 
> > failed: [localhost] (item=docker) => {"ansible_loop_var": "item", "changed": false, "item": "docker", "msg": "Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker or specify the `--cask` flag."}
> 
> What's the recommended approach here?

I encounter this same problem, and it seems to be caused by packages that are also available as casks (like awscli, httpie, etc.). I specified the `install_options: 'formula'` option, but this does not fully resolve the problem.

As a workaround I resolved this locally by doing the following:

- edit ~/.ansible/collections/ansible_collections/community/general/plugins/modules/homebrew.py
- modify the code from line 484, by adding --formula, this might be a nice permanent fix, as there is a seperate ansible module for homebrew casks (so maybe everything in this one should be forced to be a formula?).

```
        cmd = [
            "{brew_path}".format(brew_path=self.brew_path),
            "info",
            "--formula",
            "--json=v2",
            self.current_package,
        ]
```
> this might be a nice permanent fix, as there is a seperate ansible module for homebrew casks (so maybe everything in this one should be forced to be a formula?).

It _is_ a breaking change for anyone who is using this module for casks, though in my mind absolutely worth it. Even using Homebrew CLI directly this duality has been an issue for me.
> > We see a similar failure mode when the intention _is_ to install a formula.
> > > failed: [localhost] (item=docker) => {"ansible_loop_var": "item", "changed": false, "item": "docker", "msg": "Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker or specify the `--cask` flag."}
> > 
> > 
> > What's the recommended approach here?
> 
> I encounter this same problem, and it seems to be caused by packages that are also available as casks (like awscli, httpie, etc.). I specified the `install_options: 'formula'` option, but this does not fully resolve the problem.
> 
> As a workaround I resolved this locally by doing the following:
> 
> * edit ~/.ansible/collections/ansible_collections/community/general/plugins/modules/homebrew.py
> * modify the code from line 484, by adding --formula, this might be a nice permanent fix, as there is a seperate ansible module for homebrew casks (so maybe everything in this one should be forced to be a formula?).
> 
> ```
>         cmd = [
>             "{brew_path}".format(brew_path=self.brew_path),
>             "info",
>             "--formula",
>             "--json=v2",
>             self.current_package,
>         ]
> ```

Yeah, that's the issue with the commit: https://github.com/ansible-collections/community.general/commit/fa30b02294d969c0964bd8250d3bdf5d0728465d#diff-109efc689f4332320bad76472328471ef85a0faeae32ec97086c9790e244c69eR491-R494

^^ @thewalla07

where we start checking error messages (stderr) of the `run_command`, where the warning message is passed in such a cese.

@edv, I would love if you could create a PR for the fix. Do not want to take your credits )) 
I supposed the fix that proposed by you well enough, because I see no options to suppress the warning (--quiet falg does not work for me here) and add some comples statement to ignore this particular message is not elegant as for me.
I added a simple fix for this issue in #8406

Resolving patch:
diff --git a/plugins/modules/homebrew.py b/plugins/modules/homebrew.py
--- a/plugins/modules/homebrew.py
+++ b/plugins/modules/homebrew.py
@@ -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)
 


Test patch:
diff --git a/tests/integration/targets/homebrew/tasks/docker.yml b/tests/integration/targets/homebrew/tasks/docker.yml
--- 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