下载集合
若要下载集合及其依赖项以进行离线安装,请运行 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
您可以通过提供命名空间(namespace)的路径,从单个命名空间下载多个源码集合。
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