community.general.snap 模块 – 管理 snaps
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。
要在 playbook 中使用它,请指定:community.general.snap。
概要
- 管理 snaps 包。 
参数
| 参数 | 注释 | 
|---|---|
| 定义安装和跟踪更新的 snap 版本。此选项仅在任务中只有一个 snap 时才能指定。 如果未传递,则  如果传递的值不包含  有关 snap 通道的更多详细信息,请参阅 https://snapcraft.io/docs/channels。 | |
| 安装具有经典限制的 snap。 此选项对应于  此限制级别具有权限,允许完全访问系统,类似于不使用沙盒机制的传统打包应用程序。此选项仅在任务涉及单个 snap 时才能指定。 有关经典限制和限制级别的更多详细信息,请参阅 https://snapcraft.io/docs/snap-confinement。 选项 
 | |
| 以危险模式安装 snap,不验证其断言和签名。 这在安装未签名或签名未被确认的本地 snap 时很有用。 有关安装模式的更多详细信息,请参阅 https://snapcraft.io/docs/install-modes。 选项 
 | |
| 要安装的 snaps 的名称。 
 
 | |
| 使用模式  仅当  有关 snap 配置选项的更多详细信息,请参阅 https://snapcraft.io/docs/configuration-in-snaps。 | |
| 软件包的目标状态。 当  选项 
 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:完全支持 | 可以在  | |
| 支持:不支持 | 在 diff 模式下,将返回有关已更改内容(或在  | 
备注
注意
- 安装和配置 snap 等特权操作需要 root 权限。只有当用户未登录 Snap 商店时,才会出现这种情况。 
另请参阅
另请参阅
- community.general.snap_alias
- 管理 snap 别名。 
示例
# 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
返回值
常见的返回值已在此处记录,以下是此模块特有的字段:
| 键 | 描述 | 
|---|---|
| snap 安装的通道 返回:当安装 snap 时 | |
| snap 是否使用 classic confinement 安装 返回:当安装 snap 时 | |
| 在主机上执行的命令 返回:当 changed 为 true 时 | |
| 已设置/更改的选项列表,格式为  返回:当任何选项已更改/设置时 | |
| 实际安装的 snap 列表 返回:当安装任何 snap 时 | |
| 实际移除的 snap 列表 返回:当移除任何 snap 时 | 
