Open
Description
Summary
The snap module fails to install snaps like hello-world when using parameters like classic, channel, or dangerous. It seems to construct an invalid command like:
['state', 'classic', 'channel', 'dangerous', 'hello-world']
The issue occurs on:
- Ubuntu 22.04, 24.04
- Fedora 40
But works as expected on:
- Fedora 41, 42
It looks like the module isn’t handling these parameters correctly when building the command.
Issue Type
Bug Report
Component Name
snap
Ansible Version
$ ansible --version
ansible [core 2.18.3]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /venv3.12/lib/python3.12/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /venv3.12/bin/ansible
python version = 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] (/venv3.12/bin/python)
jinja version = 3.1.6
libyaml = True
Community.general Version
$ ansible-galaxy collection list community.general
devel
Configuration
$ ansible-config dump --only-changed
OS / Environment
This issue can be reproduced on Fedora 40, Ubuntu 22.04 and Ubuntu 24.04
Steps to Reproduce
Run the integration tests of snap
in one of the aforementioned OSes:
ansible-test integration snap -vvv --allow-destructive --requirements --allow-root --continue-on-error `
in order to trigger this test:
community.general/tests/integration/targets/snap/tasks/test.yml
Lines 18 to 22 in e853a6f
Expected Results
We would expect the aforementioned task to succeed and report a changed status. This occurs as expected on Fedora 41 & 42:
TASK [snap : Install package (hello-world)] ************************************
changed: [testhost]
Actual Results
TASK [snap : Install package (hello-world)] ************************************
task path: /root/.ansible/collections/ansible_collections/community/general/tests/output/.tmp/integration/snap-aqg_k9qu-ÅÑŚÌβŁÈ/tests/integration/targets/snap/tasks/test.yml:18
Using module file /root/.ansible/collections/ansible_collections/community/general/plugins/modules/snap.py
Pipelining is enabled.
<172.18.0.2> ESTABLISH SSH CONNECTION FOR USER: root
<172.18.0.2> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o 'IdentityFile="/root/.ansible/test/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/5b80634bb5"' 172.18.0.2 '/bin/sh -c '"'"'/opt/python3.12/bin/python3.12 && sleep 0'"'"''
<172.18.0.2> (1, b'\n{"exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/deco.py\\", line 56, in wrapper\\n func(self, *args, **kwargs)\\n File \\"/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/base.py\\", line 93, in run\\n self.__run__()\\n File \\"/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/mixins/state.py\\", line 37, in __run__\\n return func()\\n ^^^^^^\\n File \\"/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/modules/snap.py\\", line 427, in state_present\\n File \\"/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/modules/snap.py\\", line 415, in _present\\n File \\"/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/base.py\\", line 53, in do_raise\\n raise _MHE(*args, **kwargs)\\nansible_collections.community.general.plugins.module_utils.mh.exceptions.ModuleHelperException\\n", "output": {"classic": false, "channel": null, "version": {"snap": "2.67.1+24.04", "snapd": "2.67.1+24.04", "series": "16", "ubuntu": "24.04", "kernel": "5.15.0-139-generic"}, "snap_names": ["hello-world"], "snaps_installed": ["hello-world"], "cmd": "[\'state\', \'classic\', \'channel\', \'dangerous\', \'hello-world\']"}, "vars": {"classic": false, "channel": null, "version": {"snap": "2.67.1+24.04", "snapd": "2.67.1+24.04", "series": "16", "ubuntu": "24.04", "kernel": "5.15.0-139-generic"}, "snap_names": ["hello-world"], "snaps_installed": ["hello-world"], "cmd": "[\'state\', \'classic\', \'channel\', \'dangerous\', \'hello-world\']"}, "classic": false, "channel": null, "version": {"snap": "2.67.1+24.04", "snapd": "2.67.1+24.04", "series": "16", "ubuntu": "24.04", "kernel": "5.15.0-139-generic"}, "snap_names": ["hello-world"], "snaps_installed": ["hello-world"], "cmd": "[\'state\', \'classic\', \'channel\', \'dangerous\', \'hello-world\']", "failed": true, "msg": "Ooops! Snap installation failed while executing \'[\'state\', \'classic\', \'channel\', \'dangerous\', \'hello-world\']\', please examine logs and error output for more details.", "invocation": {"module_args": {"name": ["hello-world"], "state": "present", "classic": false, "dangerous": false, "channel": null, "options": null}}}\n', b"OpenSSH_9.6p1 Ubuntu-3ubuntu13.9, OpenSSL 3.0.13 30 Jan 2024\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 172.18.0.2 is address\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/root/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/root/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master at '/root/.ansible/cp/5b80634bb5'\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 106\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet_timeout: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n")
<172.18.0.2> Failed to connect to the host via ssh: OpenSSH_9.6p1 Ubuntu-3ubuntu13.9, OpenSSL 3.0.13 30 Jan 2024
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 172.18.0.2 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/root/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/root/.ssh/known_hosts2'
debug1: auto-mux: Trying existing master at '/root/.ansible/cp/5b80634bb5'
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 106
debug3: mux_client_request_session: session request sent
debug1: mux_client_request_session: master session id: 2
debug3: mux_client_read_packet_timeout: read header failed: Broken pipe
debug2: Received exit status from master 1
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/deco.py", line 56, in wrapper
func(self, *args, **kwargs)
File "/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/base.py", line 93, in run
self.__run__()
File "/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/mixins/state.py", line 37, in __run__
return func()
^^^^^^
File "/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/modules/snap.py", line 427, in state_present
File "/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/modules/snap.py", line 415, in _present
File "/tmp/ansible_community.general.snap_payload_ej8nrwfq/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/base.py", line 53, in do_raise
raise _MHE(*args, **kwargs)
ansible_collections.community.general.plugins.module_utils.mh.exceptions.ModuleHelperException
fatal: [testhost]: FAILED! => {
"changed": false,
"channel": null,
"classic": false,
"cmd": "['state', 'classic', 'channel', 'dangerous', 'hello-world']",
"invocation": {
"module_args": {
"channel": null,
"classic": false,
"dangerous": false,
"name": [
"hello-world"
],
"options": null,
"state": "present"
}
},
"msg": "Ooops! Snap installation failed while executing '['state', 'classic', 'channel', 'dangerous', 'hello-world']', please examine logs and error output for more details.",
"output": {
"channel": null,
"classic": false,
"cmd": "['state', 'classic', 'channel', 'dangerous', 'hello-world']",
"snap_names": [
"hello-world"
],
"snaps_installed": [
"hello-world"
],
"version": {
"kernel": "5.15.0-139-generic",
"series": "16",
"snap": "2.67.1+24.04",
"snapd": "2.67.1+24.04",
"ubuntu": "24.04"
}
},
"snap_names": [
"hello-world"
],
"snaps_installed": [
"hello-world"
],
"vars": {
"channel": null,
"classic": false,
"cmd": "['state', 'classic', 'channel', 'dangerous', 'hello-world']",
"snap_names": [
"hello-world"
],
"snaps_installed": [
"hello-world"
],
"version": {
"kernel": "5.15.0-139-generic",
"series": "16",
"snap": "2.67.1+24.04",
"snapd": "2.67.1+24.04",
"ubuntu": "24.04"
}
},
"version": {
"kernel": "5.15.0-139-generic",
"series": "16",
"snap": "2.67.1+24.04",
"snapd": "2.67.1+24.04",
"ubuntu": "24.04"
}
}
Code of Conduct
- I agree to follow the Ansible Code of Conduct