下载集合
要下载集合及其依赖项以进行脱机安装,请运行 ansible-galaxy collection download
。这会将指定的集合及其依赖项下载到指定的文件夹,并创建一个 requirements.yml
文件,该文件可用于在无法访问 Galaxy 服务器的主机上安装这些集合。默认情况下,所有集合都下载到 ./collections
文件夹。
与 install
命令一样,集合的来源基于已配置的 Galaxy 服务器配置。即使通过 URL 或 tarball 的路径指定要下载的集合,该集合也将从已配置的 Galaxy 服务器重新下载。
可以像 ansible-galaxy collection install
一样,使用一个或多个集合或 requirements.yml
文件来指定集合。
下载单个集合及其依赖项
ansible-galaxy collection download my_namespace.my_collection
下载特定版本的单个集合
ansible-galaxy collection download my_namespace.my_collection:1.0.0
要下载多个集合,可以像上面显示的那样指定多个集合作为命令行参数,或者使用 使用 requirements 文件安装多个集合 中记录的格式的 requirements 文件。
ansible-galaxy collection download -r requirements.yml
您还可以下载源集合目录。集合使用必需的 galaxy.yml
文件构建。
ansible-galaxy collection download /path/to/collection
ansible-galaxy collection download git+file:///path/to/collection/.git
您可以通过提供命名空间的路径来从单个命名空间下载多个源集合。
ns/
├── collection1/
│ ├── galaxy.yml
│ └── plugins/
└── collection2/
├── galaxy.yml
└── plugins/
ansible-galaxy collection install /path/to/ns
所有集合默认下载到 ./collections
文件夹,但您可以使用 -p
或 --download-path
指定其他路径。
ansible-galaxy collection download my_namespace.my_collection -p ~/offline-collections
下载集合后,该文件夹包含指定的集合、它们的依赖项和 requirements.yml
文件。您可以使用此文件夹以及 ansible-galaxy collection install
在无法访问 Galaxy 服务器的主机上安装集合。
# This must be run from the folder that contains the offline collections and requirements.yml file downloaded
# by the internet-connected host
cd ~/offline-collections
ansible-galaxy collection install -r requirements.yml