From dc0d00452fa6070f01c618ad95f3edc44209af4b Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sat, 8 Jul 2023 20:10:32 +1200 Subject: [PATCH] snap: add track 'latest' if no track is specified (#6835) * snap: add track 'latest' if no track is specified See https://snapcraft.io/docs/channels for more details. * snap: assume track latest if channel does not specify it --- .../fragments/6835-snap-missing-track.yml | 2 ++ plugins/modules/snap.py | 5 ++- .../targets/snap/tasks/test_channel.yml | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/6835-snap-missing-track.yml diff --git a/changelogs/fragments/6835-snap-missing-track.yml b/changelogs/fragments/6835-snap-missing-track.yml new file mode 100644 index 0000000000..bc85de065b --- /dev/null +++ b/changelogs/fragments/6835-snap-missing-track.yml @@ -0,0 +1,2 @@ +bugfixes: + - snap - assume default track ``latest`` in parameter ``channel`` when not specified (https://github.com/ansible-collections/community.general/pull/6835, https://github.com/ansible-collections/community.general/issues/6821). diff --git a/plugins/modules/snap.py b/plugins/modules/snap.py index 2afdce08f7..caf59deb35 100644 --- a/plugins/modules/snap.py +++ b/plugins/modules/snap.py @@ -55,6 +55,9 @@ options: - Define which release of a snap is installed and tracked for updates. This option can only be specified if there is a single snap in the task. - If not passed, the C(snap) command will default to V(stable). + - If the value passed does not contain the C(track), it will default to C(latest). + For example, if V(edge) is passed, the module will assume the channel to be V(latest/edge). + - See U(https://snapcraft.io/docs/channels) for more details about snap channels. type: str required: false options: @@ -277,7 +280,7 @@ class Snap(StateModuleHelper): match = [c for n, c in installed if n == name] if not match: return Snap.NOT_INSTALLED - if channel and channel != match[0]: + if channel and match[0] not in (channel, "latest/{0}".format(channel)): return Snap.CHANNEL_MISMATCH else: return Snap.INSTALLED diff --git a/tests/integration/targets/snap/tasks/test_channel.yml b/tests/integration/targets/snap/tasks/test_channel.yml index 135ee1825e..63c1d104f9 100644 --- a/tests/integration/targets/snap/tasks/test_channel.yml +++ b/tests/integration/targets/snap/tasks/test_channel.yml @@ -44,3 +44,36 @@ - install_microk8s_chan is changed - install_microk8s_chan_again is not changed - remove_microk8s is changed + +- name: Install package (shellcheck) + community.general.snap: + name: shellcheck + state: present + register: install_shellcheck + +- name: Install package with channel (shellcheck) + community.general.snap: + name: shellcheck + channel: edge + state: present + register: install_shellcheck_chan + +- name: Install package with channel (shellcheck) again + community.general.snap: + name: shellcheck + channel: edge + state: present + register: install_shellcheck_chan_again + +- name: Remove package (shellcheck) + community.general.snap: + name: shellcheck + state: absent + register: remove_shellcheck + +- assert: + that: + - install_shellcheck is changed + - install_shellcheck_chan is changed + - install_shellcheck_chan_again is not changed + - remove_shellcheck is changed