1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Alexei Znamensky 2023-07-08 20:10:32 +12:00 committed by GitHub
parent eb73dc464e
commit dc0d00452f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View file

@ -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).

View file

@ -55,6 +55,9 @@ options:
- Define which release of a snap is installed and tracked for updates. - 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. 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 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 type: str
required: false required: false
options: options:
@ -277,7 +280,7 @@ class Snap(StateModuleHelper):
match = [c for n, c in installed if n == name] match = [c for n, c in installed if n == name]
if not match: if not match:
return Snap.NOT_INSTALLED 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 return Snap.CHANNEL_MISMATCH
else: else:
return Snap.INSTALLED return Snap.INSTALLED

View file

@ -44,3 +44,36 @@
- install_microk8s_chan is changed - install_microk8s_chan is changed
- install_microk8s_chan_again is not changed - install_microk8s_chan_again is not changed
- remove_microk8s is 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