community.general.snap module – Manages snaps

Note

This module is part of the community.general collection (version 10.0.1).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.snap.

Synopsis

  • Manages snaps packages.

Parameters

Parameter

Comments

channel

string

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 snap command will default to stable.

If the value passed does not contain the track, it will default to latest. For example, if edge is passed, the module will assume the channel to be latest/edge.

See https://snapcraft.io/docs/channels for more details about snap channels.

classic

boolean

Install a snap that has classic confinement.

This option corresponds to the --classic argument of the snap install command.

This level of confinement is permissive, granting full system access, similar to that of traditionally packaged applications that do not use sandboxing mechanisms. This option can only be specified when the task involves a single snap.

See https://snapcraft.io/docs/snap-confinement for more details about classic confinement and confinement levels.

Choices:

  • false ← (default)

  • true

dangerous

boolean

added in community.general 7.2.0

Install the snap in dangerous mode, without validating its assertions and signatures.

This is useful when installing local snaps that are either unsigned or have signatures that have not been acknowledged.

See https://snapcraft.io/docs/install-modes for more details about installation modes.

Choices:

  • false ← (default)

  • true

name

list / elements=string / required

Name of the snaps to be installed.

Any named snap accepted by the snap command is valid.

dangerous=true may be necessary when installing `.snap` files. See dangerous for more details.

options

list / elements=string

added in community.general 4.4.0

Set options with pattern key=value or snap:key=value. If a snap name is given, the option will be applied to that snap only. If the snap name is omitted, the options will be applied to all snaps listed in name. Options will only be applied to active snaps.

Options will only be applied when state is set to present. This is done after the necessary installation or refresh (upgrade/downgrade) of all the snaps listed in name.

See https://snapcraft.io/docs/configuration-in-snaps for more details about snap configuration options.

state

string

Desired state of the package.

When state=present the module will use snap install if the snap is not installed, and snap refresh if it is installed but from a different channel.

Choices:

  • "absent"

  • "present" ← (default)

  • "enabled"

  • "disabled"

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Notes

Note

  • Privileged operations, such as installing and configuring snaps, require root priviledges. This is only the case if the user has not logged in to the Snap Store.

See Also

See also

community.general.snap_alias

Manages snap aliases.

Examples

# Install "foo" and "bar" snap
- name: Install foo
  community.general.snap:
    name:
      - foo
      - bar

# Install "foo" snap with options par1=A and par2=B
- name: Install "foo" with options
  community.general.snap:
    name:
      - foo
    options:
      - par1=A
      - par2=B

# Install "foo" and "bar" snaps with common option com=A and specific options fooPar=X and barPar=Y
- name: Install "foo" and "bar" with options
  community.general.snap:
    name:
      - foo
      - bar
    options:
      - com=A
      - foo:fooPar=X
      - bar:barPar=Y

# Remove "foo" snap
- name: Remove foo
  community.general.snap:
    name: foo
    state: absent

# Install a snap with classic confinement
- name: Install "foo" with option --classic
  community.general.snap:
    name: foo
    classic: true

# Install a snap with from a specific channel
- name: Install "foo" with option --channel=latest/edge
  community.general.snap:
    name: foo
    channel: latest/edge

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

channel

string

The channel the snaps were installed from

Returned: When snaps are installed

classic

boolean

Whether or not the snaps were installed with the classic confinement

Returned: When snaps are installed

cmd

string

The command that was executed on the host

Returned: When changed is true

options_changed

list / elements=string

added in community.general 4.4.0

The list of options set/changed in format snap:key=value.

Returned: When any options have been changed/set

snaps_installed

list / elements=string

The list of actually installed snaps

Returned: When any snaps have been installed

snaps_removed

list / elements=string

The list of actually removed snaps

Returned: When any snaps have been removed

Authors

  • Victor Carceler (@vcarceler)

  • Stanislas Lange (@angristan)