下载集合
要下载集合及其依赖项以进行脱机安装,请运行 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