验证集合
使用 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