Repository: ansible-collections/community.general

Issue:
community.general.snap options value truncated at first whitespace character
### Summary

I'm trying to set up a snap application (semaphore) that requires an option (ldap-binddn) which contains a space (0x20) character. Due to the regex `(?P<snap_prefix>\S+:)?(?P<key>\S+)=(?P<value>\S+)` (https://github.com/ansible-collections/community.general/blob/main/plugins/modules/snap.py#L173) the value is truncated at the space character. Unless there's a good reason I'd suggest changing the regex to end in `(?P<value>.*)$`.

### Issue Type

Bug Report

### Component Name

community.general.snap

### Ansible Version

```console (paste below)
ansible [core 2.13.3]
  config file = /home/kostenr/.ansible.cfg
  configured module search path = ['/home/kostenr/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/kostenr/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/kostenr/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/kostenr/.local/bin/ansible
  python version = 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
  jinja version = 3.0.3
  libyaml = True

```


### Community.general Version

```console (paste below)

# /home/kostenr/.local/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 5.4.0

```


### Configuration

```console (paste below)
- name: Install snap
  community.general.snap:
    name: foobar
    state: present
    options:
      - 'key=A Value'
```


### OS / Environment

Ubuntu 22.04

### Steps to Reproduce

See summary.


### Expected Results

I expect values with Spaces to work, they get truncated however (e.g. for `'key=A Value'` I expect `key` to be configured with `A Value`, but it ends up with `A` instead.

### Actual Results

```console (paste below)

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/snap.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/snap.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 @angristan @vcarceler
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/snap.py b/plugins/modules/snap.py
--- a/plugins/modules/snap.py
+++ b/plugins/modules/snap.py
@@ -170,7 +170,7 @@ def _state_map(value):
 
 class Snap(CmdStateModuleHelper):
     __disable_re = re.compile(r'(?:\S+\s+){5}(?P<notes>\S+)')
-    __set_param_re = re.compile(r'(?P<snap_prefix>\S+:)?(?P<key>\S+)=(?P<value>\S+)')
+    __set_param_re = re.compile(r'(?P<snap_prefix>\S+:)?(?P<key>\S+)\s*=\s*(?P<value>.+)')
     module = dict(
         argument_spec={
             'name': dict(type='list', elements='str', required=True),
@@ -342,7 +342,7 @@ def set_options(self):
 
                 if selected_snap_name is None or (snap_name is not None and snap_name == selected_snap_name):
                     key = match.group("key")
-                    value = match.group("value")
+                    value = match.group("value").strip()
 
                     if key not in option_map or key in option_map and option_map[key] != value:
                         option_without_prefix = key + "=" + value


Test patch:
diff --git a/tests/integration/targets/snap/tasks/main.yml b/tests/integration/targets/snap/tasks/main.yml
--- a/tests/integration/targets/snap/tasks/main.yml
+++ b/tests/integration/targets/snap/tasks/main.yml
@@ -8,7 +8,9 @@
 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
 # SPDX-License-Identifier: GPL-3.0-or-later
 
-- block:
+- name: Has-snap block
+  when: has_snap
+  block:
     - name: Make sure package is not installed (hello-world)
       community.general.snap:
         name: hello-world
@@ -189,5 +191,3 @@
           - "'uhttpd:document-root-dir=/tmp' in install_with_option_changed.options_changed"
           - "'uhttpd:listening-port=8080' not in install_with_option_changed.options_changed"
           - remove is changed
-
-  when: has_snap