8

我正在使用 ansible-galaxy (v2.0.0.2) 通过 requirements.yml 文件安装具有 Bitbucket 源代码的 ansible 角色。但我无法使用私钥从 bitbucket.org 签出代码。这是错误消息,也是我的requirements.yml内容。

有人知道requirements.ymlansible-galaxy 2.0.0.2的正确文件格式是什么吗?

  + ansible-galaxy -vvv install --force --role-file ansible/requirements.yml --roles-path ./ansible/roles

    Using /etc/ansible/ansible.cfg as config file
    Opened /tmp/.ansible_galaxy
    found role {'scm': 'git', 'src': 'git@bitbucket.org:myrepo/nginx.git', 'version': 'latest', 'name': 'nginx'} in yaml file
    Installing role nginx 

     [WARNING]: - nginx was NOT installed successfully: - command git checkout
    latest failed in directory /tmp/tmpQRZc8j (rc=1)
    ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.

[需求.yml]

- name: nginx
  src: git@bitbucket.org:myrepo/nginx.git
  scm: git
  version: latest
  accept_hostkey: yes
  key_file: /tmp/.ssh/id_rsa
4

6 回答 6

4

也许 scp 语法不起作用。网址可能:

ssh://git@bitbucket.org/myrepo/nginx.git

尝试,就像在这个 ansible 问题中一样:

从 github 克隆 repo 路径直接复制

git@github.com:geerlingguy/ansible-role-php.git

有效的实际网址

ssh://git@github.com/geerlingguy/ansible-role-php.git

您必须将 替换:/
它必须是一个 URL(即包含://),否则 ansible-galaxy 假定它是一个文件系统路径。

于 2017-01-20T05:35:44.597 回答
2

尝试git+ssh架构

适用于 ansible-galaxy 2.7.8

ansible-galaxy install git+ssh://bitbucket.org:<username>/<role-name>.git

于 2019-03-12T18:11:01.693 回答
1

如果您在 src 下方设置“scm: git”,galaxy 将运行“git clone XYZ”,其中 XYZ 是您的 src: 字段。因此,您可以“git clone XYZ”的任何内容都是您放入 src 字段的内容。

- src: ssh://git@bitbucket.internal.com:8899/project/repo-name.git
  scm: git

对于私钥,如果它不是您的默认 ssh 密钥,我们使用 ssh-agent(1)(请参阅手册页了解用法)。

于 2019-07-29T20:07:58.637 回答
0

正如 Ansible 所说,如果您查看您的/tmp/tmpQRZc8j目录,您会看到您的角色已被获取。

问题是您指定了错误的版本参数,并且 ansible 试图使git checkout latest这是不可能的(除非使用名为 latest 的分支或标签)。

您必须改为提供现有的分支或标签。

于 2017-06-28T17:17:07.557 回答
0

该错误与您的requirements.yml文件中的未知key_fileaccept_hostkey属性有关。

根据Ansible 文档, requirements.yml文件的唯一可用属性是:

  • 源代码
  • 单片机
  • 版本
  • 姓名

您将需要使用 ssh配置文件来配置 ssh-key 以用于您的私有存储库。以下是一些有用的链接:

于 2022-01-17T15:31:18.563 回答
-1

错误将是由于您在 requirements.yml 中提供的一些错误详细信息,它可以是 git URL,或者版本:编号或版本:分支名称

于 2020-10-22T17:31:18.610 回答