Repository: ansible-collections/community.general

Issue:
snap.py fails when multiple names specified and the description of one of them has `---` in it
### Summary

If you specify a `snap` task with multiple names listed, and the description field of the info for one of the snaps contains the string `---`, the task fails.

There's a trivial fix for this. PR from me incoming shortly.


### Issue Type

Bug Report

### Component Name

snap

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.15.2]
  config file = /home/jik/src/family-orchestration/ansible.cfg
  configured module search path = ['/home/jik/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/jik/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.4 (main, Jun  7 2023, 10:13:09) [GCC 12.3.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

```


### Community.general Version

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


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
CONFIG_FILE() = /home/jik/src/family-orchestration/ansible.cfg
DEFAULT_HOST_LIST(/home/jik/src/family-orchestration/ansible.cfg) = ['/home/jik/src/family-orchestration/inventory']DEFAULT_REMOTE_USER(/home/jik/src/family-orchestration/ansible.cfg) = root
EDITOR(env: EDITOR) = emacsclient

```


### OS / Environment

Ubuntu Mantic (23.10) x86_64

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: localhost
  tasks:
  - snap:
      name:
      - vault
      - bw

```


### Expected Results

```
PLAY RECAP *********************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
```


### Actual Results

```console (paste below)
TASK [snap] ********************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IndexError: list index out of range
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Module failed with exception: list index out of range", "output": {}, "vars": {}}

PLAY RECAP *********************************************************************************************************
localhost                  : 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


Discussion:

Resolving patch:
diff --git a/plugins/modules/snap.py b/plugins/modules/snap.py
--- a/plugins/modules/snap.py
+++ b/plugins/modules/snap.py
@@ -303,7 +303,10 @@ def process_one(rc, out, err):
             return [name]
 
         def process_many(rc, out, err):
-            outputs = out.split("---")
+            # This needs to be "\n---" instead of just "---" because otherwise
+            # if a snap uses "---" in its description then that will incorrectly
+            # be interpreted as a separator between snaps in the output.
+            outputs = out.split("\n---")
             res = []
             for sout in outputs:
                 res.extend(process_one(rc, sout, ""))


Test patch: