Repository: ansible-collections/community.general

Issue:
error: snap is not available on {0}/stable but is available to install on the following tracks
### Summary

version community.general
```
ansible-galaxy collection install community.general
Process install dependency map
Starting collection install process
Installing 'community.general:3.3.2' to '/home/apatsev/.ansible/collections/ansible_collections/community/general'
```

Work on 2.5.4 version.
But on 3.3.2 version get error:
```
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.community.general.plugins.module_utils.mh.exceptions.ModuleHelperException
fatal: [ecse00500c11.epam.com]: FAILED! => changed=false 
  channel: 1.18/stable
  classic: true
  cmd: '[''state'', ''classic'', ''channel'', {''actionable_snaps'': [''microk8s'']}]'
  cmd_args:
  - /usr/bin/snap
  - install
  - --classic
  - --channel
  - '{0}'
  - microk8s
  force_lang: C
  msg: 'Ooops! Snap installation failed while executing ''[''state'', ''classic'', ''channel'', {''actionable_snaps'': [''microk8s'']}]'', please examine logs and error output for more details.'
  output:
    channel: 1.18/stable
    classic: true
    cmd: '[''state'', ''classic'', ''channel'', {''actionable_snaps'': [''microk8s'']}]'
    cmd_args:
    - /usr/bin/snap
    - install
    - --classic
    - --channel
    - '{0}'
    - microk8s
    force_lang: C
    rc: 1
    snaps_installed:
    - microk8s
    stderr: |-
      error: snap "microk8s" is not available on {0}/stable but is available to
             install on the following tracks:
  
             latest/stable  snap install --stable microk8s
             1.21/stable    snap install --channel=1.21 microk8s
             1.20/stable    snap install --channel=1.20 microk8s
             1.19/stable    snap install --channel=1.19 microk8s
             1.18/stable    snap install --channel=1.18 microk8s
             1.17/stable    snap install --channel=1.17 microk8s
             1.16/stable    snap install --channel=1.16 microk8s
             1.15/stable    snap install --channel=1.15 microk8s
             1.14/stable    snap install --channel=1.14 microk8s
             1.13/stable    snap install --channel=1.13 microk8s
             1.12/stable    snap install --channel=1.12 microk8s
             1.11/stable    snap install --channel=1.11 microk8s
             1.10/stable    snap install --channel=1.10 microk8s
  
             Please be mindful that different tracks may include different features.
             Get more information with 'snap info microk8s'.
    stdout: ''
  rc: 1
  snaps_installed:
  - microk8s
  stderr: |-
    error: snap "microk8s" is not available on {0}/stable but is available to
           install on the following tracks:
  
           latest/stable  snap install --stable microk8s
           1.21/stable    snap install --channel=1.21 microk8s
           1.20/stable    snap install --channel=1.20 microk8s
           1.19/stable    snap install --channel=1.19 microk8s
           1.18/stable    snap install --channel=1.18 microk8s
           1.17/stable    snap install --channel=1.17 microk8s
           1.16/stable    snap install --channel=1.16 microk8s
           1.15/stable    snap install --channel=1.15 microk8s
           1.14/stable    snap install --channel=1.14 microk8s
           1.13/stable    snap install --channel=1.13 microk8s
           1.12/stable    snap install --channel=1.12 microk8s
           1.11/stable    snap install --channel=1.11 microk8s
           1.10/stable    snap install --channel=1.10 microk8s
  
           Please be mindful that different tracks may include different features.
           Get more information with 'snap info microk8s'.
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>
  vars:
    channel: 1.18/stable
    classic: true
    cmd: '[''state'', ''classic'', ''channel'', {''actionable_snaps'': [''microk8s'']}]'
    cmd_args:
    - /usr/bin/snap
    - install
    - --classic
    - --channel
    - '{0}'
    - microk8s
    force_lang: C
    rc: 1
    snaps_installed:
    - microk8s
    stderr: |-
      error: snap "microk8s" is not available on {0}/stable but is available to
             install on the following tracks:
  
             latest/stable  snap install --stable microk8s
             1.21/stable    snap install --channel=1.21 microk8s
             1.20/stable    snap install --channel=1.20 microk8s
             1.19/stable    snap install --channel=1.19 microk8s
             1.18/stable    snap install --channel=1.18 microk8s
             1.17/stable    snap install --channel=1.17 microk8s
             1.16/stable    snap install --channel=1.16 microk8s
             1.15/stable    snap install --channel=1.15 microk8s
             1.14/stable    snap install --channel=1.14 microk8s
             1.13/stable    snap install --channel=1.13 microk8s
             1.12/stable    snap install --channel=1.12 microk8s
             1.11/stable    snap install --channel=1.11 microk8s
             1.10/stable    snap install --channel=1.10 microk8s
  
             Please be mindful that different tracks may include different features.
             Get more information with 'snap info microk8s'.
    stdout: ''
```

### Issue Type

Bug Report

### Component Name

snap

### Ansible Version

```console (paste below)
$ ansible --version

ansible 2.9.23
  config file = /home/apatsev/epam-git/infrastructure/ansible/ansible.cfg
  configured module search path = [u'/home/apatsev/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```


### OS / Environment

Ubuntu 18.04

### Steps to Reproduce

Ansible code
```
- name: Install "microk8s" with option --channel=1.18/stable
  become: true
  community.general.snap:
    name: microk8s
    channel: 1.18/stable
    classic: true
```

### Expected Results

worked code

### 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/packaging/os/snap.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/packaging/os/snap.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 @angristan @vcarceler
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
CC @russoz
I created a fix in #3028. Would be glad if you could test this ASAP so we can include it in the next release (which I'll start making tomorrow evening).
@felixfontein Thanks! Dont worry.
@felixfontein Thanks! I encountered the same issue with the module `community.general.snap` with version `3.3.2` of this collection but this appears to be resolved by your change (tested [felixfontein:fix-snap](https://github.com/felixfontein/community.general/tree/fix-snap) at commit 332b7b09d1b8e71e3ed891259c013eaea6569d44).

My environment is Ubuntu 20.04 LTS (`focal`) on the `amd64` architecture with `ansible` (community package) `4.2.0-1ppa~focal` and `ansible-core` `2.11.2-1ppa~focal` packages installed from the upstream PPA [ansible-4](https://launchpad.net/~ansible/+archive/ubuntu/ansible-4) but also with a newer version of this `community.general` collection has installed using `ansible-galaxy` (into `~/.ansible/collections/ansible_collections` overriding version provided by the `ansible` Debian package in `/usr/lib/python3/dist-packages/ansible_collections`).

Resolving patch:
diff --git a/plugins/modules/packaging/os/snap.py b/plugins/modules/packaging/os/snap.py
--- a/plugins/modules/packaging/os/snap.py
+++ b/plugins/modules/packaging/os/snap.py
@@ -145,7 +145,7 @@ class Snap(CmdStateModuleHelper):
         actionable_snaps=dict(fmt=lambda v: v),
         state=dict(fmt=_state_map),
         classic=dict(fmt="--classic", style=ArgFormat.BOOLEAN),
-        channel=dict(fmt=lambda v: [] if v == 'stable' else ['--channel', '{0}']),
+        channel=dict(fmt=lambda v: [] if v == 'stable' else ['--channel', '{0}'.format(v)]),
     )
     check_rc = False
 


Test patch: