community.general.pacman_key 模块 – 管理 pacman 的可信密钥列表

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您使用的是 ansible 包,您可能已经安装了这个集合。 它不包含在 ansible-core 中。 要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.general。 您需要进一步的要求才能使用此模块,请参阅 要求 了解详细信息。

要在 playbook 中使用它,请指定: community.general.pacman_key

community.general 3.2.0 版本新增

概要

  • 从 pacman 密钥环添加或删除 gpg 密钥。

要求

在执行此模块的主机上需要以下要求。

  • gpg

  • pacman-key

参数

参数

注释

data

字符串

要添加到密钥环的密钥文件内容。

必须是 PGP PUBLIC KEY BLOCK 类型。

file

路径

远程服务器上要添加到密钥环的密钥文件的路径。

远程文件必须是 PGP PUBLIC KEY BLOCK 类型。

force_update

布尔值

如果密钥已经存在于密钥环中,这将强制更新该密钥。

选项

  • false ← (默认)

  • true

id

字符串 / 必需

密钥的 40 个字符的标识符。

包括此项允许检查模式正确报告更改的状态。

不要指定子密钥 ID,而是指定主密钥 ID。

keyring

路径

远程服务器上密钥环文件夹的完整路径。

如果未指定,模块将使用 pacman 的默认值 (/etc/pacman.d/gnupg)。

如果远程系统需要备用 gnupg 目录,则此选项很有用。

默认值: "/etc/pacman.d/gnupg"

keyserver

字符串

用于从中检索密钥的密钥服务器。

state

字符串

确保密钥存在(已添加)或不存在(已撤销)。

选项

  • "absent"

  • "present" ← (默认)

url

字符串

从中检索密钥文件的 URL。

远程文件必须是 PGP PUBLIC KEY BLOCK 类型。

verify

布尔值

是否根据指定的密钥 ID 验证密钥文件的密钥 ID。

选项

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持: 完全

可以在 check_mode 中运行并返回更改状态预测,而无需修改目标。

diff_mode

支持:

在 diff 模式下,将返回有关已更改(或可能需要在 check_mode 中更改)的详细信息。

备注

注意

  • 使用全长密钥 ID(40 个字符)。

  • 当使用 datafileurl 时,密钥将被验证,除非覆盖 verify

  • 密钥在导入密钥环后将在本地签名。

  • 如果密钥 ID 已存在于密钥环中,除非指定了 force_update,否则不会添加该密钥。

  • datafileurlkeyserver 是互斥的。

示例

- name: Import a key via local file
  community.general.pacman_key:
    id: 01234567890ABCDE01234567890ABCDE12345678
    data: "{{ lookup('file', 'keyfile.asc') }}"
    state: present

- name: Import a key via remote file
  community.general.pacman_key:
    id: 01234567890ABCDE01234567890ABCDE12345678
    file: /tmp/keyfile.asc
    state: present

- name: Import a key via url
  community.general.pacman_key:
    id: 01234567890ABCDE01234567890ABCDE12345678
    url: https://domain.tld/keys/keyfile.asc
    state: present

- name: Import a key via keyserver
  community.general.pacman_key:
    id: 01234567890ABCDE01234567890ABCDE12345678
    keyserver: keyserver.domain.tld

- name: Import a key into an alternative keyring
  community.general.pacman_key:
    id: 01234567890ABCDE01234567890ABCDE12345678
    file: /tmp/keyfile.asc
    keyring: /etc/pacman.d/gnupg-alternative

- name: Remove a key from the keyring
  community.general.pacman_key:
    id: 01234567890ABCDE01234567890ABCDE12345678
    state: absent

作者

  • George Rawlinson (@grawlinson)