community.general.snap (8.5.0) — module

Manages snaps

Authors: Victor Carceler (@vcarceler) <vcarceler@iespuigcastellar.xeill.net>, Stanislas Lange (@angristan) <angristan@pm.me>

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Manages snaps packages.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Install "foo" and "bar" snap
- name: Install foo
  community.general.snap:
    name:
      - foo
      - bar
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Remove "foo" snap
- name: Remove foo
  community.general.snap:
    name: foo
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Install a snap with classic confinement
- name: Install "foo" with option --classic
  community.general.snap:
    name: foo
    classic: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Install a snap with from a specific channel
- name: Install "foo" with option --channel=latest/edge
  community.general.snap:
    name: foo
    channel: latest/edge

Inputs

    
name:
    description:
    - Name of the snaps to be installed.
    - Any named snap accepted by the C(snap) command is valid.
    - 'Notice that snap files might require O(dangerous=true) to ignore the error "cannot
      find signatures with metadata for snap".

      '
    elements: str
    required: true
    type: list

state:
    choices:
    - absent
    - present
    - enabled
    - disabled
    default: present
    description:
    - Desired state of the package.
    - 'When O(state=present) the module will use C(snap install) if the snap is not installed,
      and C(snap refresh) if it is installed but from a different channel.

      '
    type: str

channel:
    description:
    - 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.
    required: false
    type: str

classic:
    default: false
    description:
    - Confinement policy. The classic confinement allows a snap to have the same level
      of access to the system as "classic" packages, like those managed by APT. This option
      corresponds to the C(--classic) argument. This option can only be specified if there
      is a single snap in the task.
    required: false
    type: bool

options:
    description:
    - Set options with pattern C(key=value) or C(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 O(name). Options will only be applied to
      active snaps.
    elements: str
    required: false
    type: list
    version_added: 4.4.0
    version_added_collection: community.general

dangerous:
    default: false
    description:
    - Install the given snap file even if there are no pre-acknowledged signatures for
      it, meaning it was not verified and could be dangerous.
    required: false
    type: bool
    version_added: 7.2.0
    version_added_collection: community.general

Outputs

channel:
  description: The channel the snaps were installed from
  returned: When snaps are installed
  type: str
classic:
  description: Whether or not the snaps were installed with the classic confinement
  returned: When snaps are installed
  type: bool
cmd:
  description: The command that was executed on the host
  returned: When changed is true
  type: str
options_changed:
  description: The list of options set/changed in format C(snap:key=value).
  returned: When any options have been changed/set
  type: list
  version_added: 4.4.0
  version_added_collection: community.general
snaps_installed:
  description: The list of actually installed snaps
  returned: When any snaps have been installed
  type: list
snaps_removed:
  description: The list of actually removed snaps
  returned: When any snaps have been removed
  type: list

See also