ansible-galaxy - 指定要安装的版本范围

时间:2021-01-30 13:19:09

标签: ansible ansible-galaxy

我正在尝试安装 Ansible Galaxy 系列,但我需要强制使用旧版本。 According to the documentation,我尝试通过以下方式进行安装:

$ ansible-galaxy collection install 'weareinteractive.ufw:>=1.10.0,<2.0.0'
Process install dependency map
ERROR! Failed to find collection weareinteractive.ufw:>=1.10.0,<2.0.0
$ ansible-galaxy collection install 'weareinteractive.ufw:<2.0.0'
Process install dependency map
ERROR! Failed to find collection weareinteractive.ufw:<2.0.0

当我尝试从这个 requirements.yml 执行相同操作时,我在全局范围内遇到了相同类型的错误:

---
- name: weareinteractive.ufw
  version: '>=1.8.0,<2.0.0'

运行命令

$ ansible-galaxy install -r requirements.yml
- downloading role 'ufw', owned by weareinteractive
[WARNING]: - weareinteractive.ufw was NOT installed successfully: - the specified version (>=1.8.0,<2.0.0) of weareinteractive.ufw was not found in the list of available versions ([{'id': 141713, 'url': '', 'related': {}, 'summary_fields': {}, 'created':
'2020-11-25T18:52:30.171540Z', 'modified': '2020-11-25T18:52:30.171568Z', 'name': '2.0.1', 'version': '2.0.1', 'commit_date': '2020-11-25T10:51:53-05:00', 'commit_sha': '30b1fdc8f5440e865d3fbeb83894941bf70739c7', 'download_url':
'https://github.com/weareinteractive/ansible-ufw/archive/2.0.1.tar.gz', 'active': None}, {'id': 76043, 'url': '', 'related': {}, 'summary_fields': {}, 'created': '2018-10-04T14:07:47.602784Z', 'modified': '2018-10-04T14:07:47.602810Z', 'name': '1.8.0', 'version':
'1.8.0', 'commit_date': '2018-10-04T10:05:07-04:00', 'commit_sha': 'ae776a7dc255ba5dc679cedee32129ba22c0e797', 'download_url': 'https://github.com/weareinteractive/ansible-ufw/archive/1.8.0.tar.gz', 'active': None}, .....]).
ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.

我错过了什么?

编辑:我正在使用 ansible / ansible-galaxy 2.9.16,但我希望有一个仍然适用于 ansible 2.10 的解决方案

1 个答案:

答案 0 :(得分:3)

如您尝试安装的角色的存储库首页所述:

<块引用>

Ansible weareinteractive.ufw 角色

来源:https://github.com/weareinteractive/ansible-ufw#ansible-weareinteractiveufw-role

它是一个角色,而不是一个集合。

虽然这两种语法看起来很像,但实际上它们的语法并不完全相同。
对于角色,首先,您不要通过

安装它们
ansible-galaxy collection install some-collection

显然,但通过:

ansible-galaxy install some-role

注意:他们的 GitHub 页面和他们的 Ansible Galaxy 页面都证实了这一点,建议您通过

安装角色
ansible-galaxy install weareinteractive.ufw

来源:https://galaxy.ansible.com/weareinteractive/ufwhttps://github.com/weareinteractive/ansible-ufw


然后,版本固定也不同。对于角色,您必须指定版本,而不是版本范围:

<块引用>

当 Galaxy 服务器导入角色时,它会导入任何与 Semantic Version 格式匹配的 git 标签作为版本。反过来,您可以通过指定导入的标签之一来下载角色的特定版本。

来源:https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#installing-a-specific-version-of-a-role

所以你必须基于他们的 repo 的 git 标签,例如

ansible-galaxy install weareinteractive.ufw,v1.10.0

requirement.yml 也是 differs a bit,您还必须在其中提供特定版本。

- name: weareinteractive.ufw
  version: v1.10.0