Repository: ansible-collections/community.general

Issue:
error trying to install cask with '@' in the name
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Explain the problem briefly below -->
Ansible generates an error trying to install a homebrew cask with an `@` in the name.
##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
`plugins/modules/packaging/os/homebrew_cask.py`
##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```
ansible --version
ansible 2.9.11
  config file = None
  configured module search path = ['/Users/bboles/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.9.11/libexec/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```
(no config)
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
MacOS 10.15.6

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
Try to install a homebrew cask with an `@` in the name from a playbook using the `homebrew` module, for example (from the tap `wooga/unityversions`) `unity@2019.3.9f1`.

<!--- Paste example playbooks or commands between quotes below -->
```
- name: Installing Unity Cask
  homebrew_cask:
    name: unity@2019.3.9f1
    state: present
    accept_external_apps: true
  register: result
  until: result is successful
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
Cask should be installed successfully.  It seems that the code is flagging casks with an `@` symbol as invalid even though the [requirements are any UTF-8 characters](https://github.com/Homebrew/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/name.md).

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->
Ansible generates this error and fails to install the cask:
```
fatal: [74.80.243.63]: FAILED! => {
    "attempts": 3,
    "changed": false,
    "invocation": {
        "module_args": {
            "accept_external_apps": true,
            "greedy": false,
            "install_options": [],
            "name": [
                "unity@2019.3.9f1"
            ],
            "path": "/usr/local/bin",
            "state": "present",
            "sudo_password": null,
            "update_homebrew": false,
            "upgrade_all": false
        }
    },
    "msg": "Invalid cask: unity@2019.3.9f1."
}
```


Discussion:
Files identified in the description:
* [`plugins/modules/packaging/os/homebrew_cask.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/packaging/os/homebrew_cask.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 @akasurde @danieljaouen @enriclluelles @indrajitr @kyleabenson @martinm82
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Looks like the fix may be as simple as adding `@` to [here](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/packaging/os/homebrew_cask.py#L184).

Resolving patch:
diff --git a/plugins/modules/packaging/os/homebrew_cask.py b/plugins/modules/packaging/os/homebrew_cask.py
--- a/plugins/modules/packaging/os/homebrew_cask.py
+++ b/plugins/modules/packaging/os/homebrew_cask.py
@@ -186,6 +186,7 @@ class HomebrewCask(object):
         .                   # dots
         /                   # slash (for taps)
         -                   # dashes
+        @                   # at symbol
     '''
 
     INVALID_PATH_REGEX = _create_regex_group(VALID_PATH_CHARS)


Test patch: