验证集合

使用 ansible-galaxy 验证集合

安装后,您可以验证已安装集合的内容是否与服务器上的集合内容匹配。此功能要求集合安装在已配置的集合路径之一中,并且集合存在于已配置的 Galaxy 服务器之一上。

ansible-galaxy collection verify my_namespace.my_collection

ansible-galaxy collection verify 命令如果成功,则输出为空。如果集合已被修改,则更改的文件将列在集合名称下。

ansible-galaxy collection verify my_namespace.my_collection
Collection my_namespace.my_collection contains modified content in the following files:
my_namespace.my_collection
    plugins/inventory/my_inventory.py
    plugins/modules/my_module.py

您可以使用 -vvv 标志显示其他信息,例如已安装集合的版本和路径、用于验证的远程集合的 URL 以及成功的验证输出。

ansible-galaxy collection verify my_namespace.my_collection -vvv
...
Verifying 'my_namespace.my_collection:1.0.0'.
Installed collection found at '/path/to/ansible_collections/my_namespace/my_collection/'
Remote collection found at 'https://galaxy.ansible.com/download/my_namespace-my_collection-1.0.0.tar.gz'
Successfully verified that checksums for 'my_namespace.my_collection:1.0.0' match the remote collection

如果您安装了预发行版或非最新版本的集合,则应包含特定版本进行验证。如果省略版本,则将使用服务器上可用的最新版本验证已安装的集合。

ansible-galaxy collection verify my_namespace.my_collection:1.0.0

除了 namespace.collection_name:version 格式外,您还可以在一个 requirements.yml 文件中提供要验证的集合。 requirements.yml 中列出的依赖项不包含在 verify 过程中,应单独验证。

ansible-galaxy collection verify -r requirements.yml

不支持针对 tar.gz 文件进行验证。如果您的 requirements.yml 包含 tar 文件的路径或安装的 URL,您可以使用 --ignore-errors 标志确保使用文件中 namespace.name 格式的所有集合都得到处理。

验证已签名的集合

如果集合已由 分发服务器 签名,则服务器将提供 ASCII 盔甲化的独立签名,以验证 MANIFEST.json 的真实性,然后再使用它来验证集合的内容。此选项并非所有分发服务器都可用。有关支持集合签名的服务器列表,请参见 分发集合。有关如何在安装时验证已签名的集合,请参见 使用签名验证安装集合

要验证已签名的已安装集合

ansible-galaxy collection verify my_namespace.my_collection  --keyring ~/.ansible/pubring.kbx

使用 --signature 选项使用附加签名验证在 CLI 上提供的集合名称。此选项可多次使用以提供多个签名。

ansible-galaxy collection verify my_namespace.my_collection --signature https://examplehost.com/detached_signature.asc --signature file:///path/to/local/detached_signature.asc --keyring ~/.ansible/pubring.kbx

或者,您可以使用 requirements.yml 文件验证集合签名。

ansible-galaxy collection verify -r requirements.yml --keyring ~/.ansible/pubring.kbx

从分发服务器安装集合时,服务器提供的用于验证集合真实性的签名将与已安装的集合一起保存。当提供 --offline 选项时,此数据用于验证集合的内部一致性,而无需再次查询分发服务器。

ansible-galaxy collection verify my_namespace.my_collection --offline --keyring ~/.ansible/pubring.kbx