验证 collections
使用 ansible-galaxy 验证 collections
安装完成后,您可以验证已安装 collection 的内容是否与服务器上的 collection 内容一致。此功能要求 collection 已安装在配置的 collection 路径之一中,且该 collection 存在于配置的 galaxy 服务器之一上。
ansible-galaxy collection verify my_namespace.my_collection
ansible-galaxy collection verify 命令在执行成功时不会有输出。如果 collection 被修改过,更改的文件将列在 collection 名称下方。
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 标志来显示更多信息,例如已安装 collection 的版本和路径、用于验证的远程 collection 的 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
如果您安装的是 pre-release(预发布)版本或非最新版本的 collection,则应指定具体的版本进行验证。如果省略版本号,则已安装的 collection 将与服务器上的最新可用版本进行验证。
ansible-galaxy collection verify my_namespace.my_collection:1.0.0
除了 namespace.collection_name:version 格式外,您还可以在 requirements.yml 文件中提供需要验证的 collections。requirements.yml 中列出的依赖项不包含在 verify 过程中,应单独进行验证。
ansible-galaxy collection verify -r requirements.yml
不支持针对 tar.gz 文件进行验证。如果您的 requirements.yml 包含 tar 文件的路径或安装 URL,您可以使用 --ignore-errors 标志,以确保文件中所有使用 namespace.name 格式的 collection 都能被处理。
验证已签名的 collections
如果 collection 已由 分发服务器 签名,服务器将提供 ASCII armored 格式的分离签名,以便在将其用于验证 collection 内容之前,先验证 MANIFEST.json 的真实性。并非所有分发服务器都提供此选项。请参阅 分发 collections 以查看支持 collection 签名的服务器列表。关于在安装时如何验证已签名 collection,请参阅 安装带有签名验证的 collections。
验证已安装的签名 collection
ansible-galaxy collection verify my_namespace.my_collection --keyring ~/.ansible/pubring.kbx
使用 --signature 选项,通过额外的签名来验证在命令行界面 (CLI) 中提供的 collection 名称。该选项可以使用多次以提供多个签名。
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 文件来验证 collection 签名。
ansible-galaxy collection verify -r requirements.yml --keyring ~/.ansible/pubring.kbx
当 collection 从分发服务器安装时,服务器提供的用于验证 collection 真实性的签名会与已安装的 collection 一起保存。当提供 --offline 选项时,这些数据将被用于验证 collection 的内部一致性,而无需再次查询分发服务器。
ansible-galaxy collection verify my_namespace.my_collection --offline --keyring ~/.ansible/pubring.kbx