1

作为 Ansible 集合的新手,我希望我在尝试使用私有 GitHub 存储库将一些旧的 Ansible 角色重构为集合时遗漏了一些明显的东西。

我有 2 个链接帐户的 GitHub 设置。我会打电话给主要的个人帐户GITHUB_AC_P。个人帐户与我将调用的子组织帐户相关联GITHUB_AC_O。我可以在 GitHub Web UI 中切换这些帐户,并使用以下单个条目~/.ssh/config 通过 git 客户端访问这两个帐户:

Host GITHUB_AC_P.github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_github_REDACTED_GITHUB_A

我首先将 Ansible Galaxy 集合文件添加到名为ansible.commonaccount的新 GitHub 存储库中GITHUB_AC_O。我计划在其他 Ansible Galaxy 集合中重用这个集合。它目前只有一个角色和以下galaxy.yml文件:

namespace: REDACTED_NS
name: common
version: 0.0.1
description: "Common Ansible collection"
readme: README.md
authors:
  - REDACTED_AUTHOR

以下命令报告“安装成功”,我在以下位置看到集合~/.ansible/collections/ansible_collections/REDACTED_NS/common

ansible-galaxy collection install git@GITHUB_AC_P.github.com:GITHUB_AC_O/ansible.common.git,main

然后,我在一个名为ansible.harden_host. 这也在考虑之内GITHUB_AC_O。这目前没有任何角色,并使用以下galaxy.yml文件来引用上述公共集合(两个galaxy.yml文件中REDACTED_NS的值相同):

namespace: REDACTED_NS
name: harden_host
version: 0.0.1
description: "Ansible collection to harden hosts"
readme: README.md
authors:
  - REDACTED_AUTHOR
dependencies: {
  REDACTED_NS.common: git@GITHUB_AC_P.github.com:GITHUB_AC_O/ansible.common.git,main
}

但是当我运行以下命令时:

ansible-galaxy collection install --verbose git@GITHUB_AC_P.github.com:GITHUB_AC_O/ansible.harden_host.git,main

它失败并显示消息:

Starting galaxy collection install process
Process install dependency map
ERROR! Unknown error when attempting to call Galaxy at 'https://galaxy.ansible.com/api/': <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>

为什么这是试图点击galaxy.ansible.com而不是我的 GitHub 帐户?

当我添加--ignore-certs并运行以下内容时:

ansible-galaxy collection install --ignore-certs git@GUTHUB_AC_P.github.com:GITHUB_AC_O/ansible.harden_host.git,main

它失败并显示以下不同消息:

ERROR! Failed to find collection REDACTED_NS.common:git@GITHUB_AC_P.github.com:GITHUB_AC_O/ansible.common.git

我将此错误中的 URI(冒号右侧)粘贴到ansible-galaxy collection install命令中,以验证 URI 中没有拼写错误。这工作得很好。

字符串 REDACTED_NS 不等于 GITHUB_AC_P 或 GITHUB_AC_O 的值。

如果有人可以请解释这里出了什么问题以及如何解决这个问题,将不胜感激。

4

1 回答 1

1

解决了; 似乎答案隐藏在 Ansible 的Using collections文档中的普通站点中,该文档说对基于 git 的依赖项使用以下形式:

dependencies: {'git@github.com:organization/repo_name.git': 'devel'}

我使用的表单是用于 Galaxy 服务器的,因此它很成功galaxy.ansible.com(除非我用 eg 覆盖了默认值--server localhost)。

所以下面的表格有效(git repo 后跟 git reference):

namespace: REDACTED_NS
name: harden_host
version: 0.0.1
description: "Ansible collection to harden hosts"
readme: README.md
authors:
  - REDACTED_AUTHOR
dependencies: {
  'git@GITHUB_AC_P.github.com:GITHUB_AC_O/ansible.common.git': 'main'
}
于 2021-05-17T07:09:50.100 回答