Repository: ansible/ansible

Issue:
homebrew_tap fails to tap caskroom/cask now.
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
<!--- Explain the problem briefly -->
Running the task `homebrew_tap: name=caskroom/cask` fails due to the fact that caskroom/cask has migrated to homebrew/cask.  See https://github.com/Homebrew/brew/pull/4210
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
homebrew_tap

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```

```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).-->
```
(14:49:33) C02W513SHTD8:tmp aso$ ansible-config dump --only-changed
(14:49:35) C02W513SHTD8:tmp aso$
```

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
From macOS 10.13.4
To macOS 10.13.4

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: install homebrew cask
  homebrew_tap: name=caskroom/cask
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
The task should have succeeded and running `brew tap` should have resulted in caskroom/cask being listed.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
The task failed even though it successfully tapped a homebrew cask. Running `brew tap` results in homebrew/cask being listed.

<!--- Paste verbatim command output between quotes below -->
```
Alberts-Mac:bin bambooagent$ brew tap
homebrew/cask
homebrew/core
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/packaging/os/homebrew_tap.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/packaging/os/homebrew_tap.py)

If these files are inaccurate, 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/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @danieljaouen @indrajitr
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/packaging/os/homebrew_tap.py b/lib/ansible/modules/packaging/os/homebrew_tap.py
--- a/lib/ansible/modules/packaging/os/homebrew_tap.py
+++ b/lib/ansible/modules/packaging/os/homebrew_tap.py
@@ -111,7 +111,7 @@ def add_tap(module, brew_path, tap, url=None):
             tap,
             url,
         ])
-        if already_tapped(module, brew_path, tap):
+        if rc == 0:
             changed = True
             msg = 'successfully tapped: %s' % tap
         else:


Test patch: