Git 无法通过ansible克隆专用bitbucket repo

Git 无法通过ansible克隆专用bitbucket repo,git,bitbucket,ansible-playbook,ssh-agent,Git,Bitbucket,Ansible Playbook,Ssh Agent,我在ansible.cfg中有以下配置 sudo_flags = -H -S -n [ssh_connection] ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes - name: Fetch code from git repo git: repo={{repo_url}} dest={{ proj_path }} version={{ repo_

我在ansible.cfg中有以下配置

sudo_flags = -H -S -n
[ssh_connection]
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes

- name: Fetch code from git repo
  git:  repo={{repo_url}}
        dest={{ proj_path }}
        version={{ repo_version }}
        accept_hostkey=yes
        force=true
请记住,我也有和之前的sudo一样的任务

错误消息是:

Warning: Permanently added the RSA host key for IP address '2401:1d80:1010::150' to the list of known hosts.\r\nPermission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "Warning: Permanently added the RSA host key for IP address '2401:1d80:1010::150' to the list of known hosts.\r\nPermission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stdout": "", "stdout_lines": []}

该错误消息表示Ansible正在使用的密钥没有从该Bitbucket repo克隆的权限,或者Ansible没有使用它应该使用的密钥。从这条信息中没有明确的迹象表明它有哪些问题,所以你必须挖掘一点来弄清楚到底发生了什么


首先,使用ssh-i/path/to/key测试密钥的权限git@bitbucket.org

如果您获得
权限被拒绝(公钥)
,则该密钥不会与任何用户关联,也不会作为部署密钥添加到任何repo。将公钥添加到需要它的用户或repo

如果你得到这样的东西-

logged in as some-username-here.

You can use git or hg to connect to Bitbucket. Shell access is disabled.
Connection to bitbucket.org closed.
authenticated via a deploy key.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

This deploy key has read access to the following repositories:
然后,该密钥与该用户的帐户相关联

如果你得到这样的东西-

logged in as some-username-here.

You can use git or hg to connect to Bitbucket. Shell access is disabled.
Connection to bitbucket.org closed.
authenticated via a deploy key.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

This deploy key has read access to the following repositories:
然后将该密钥添加为这些repo的部署(即只读)密钥


如果密钥的权限良好,则ssh代理未运行或不知道密钥。尝试将您的
ssh\u参数更新为如下内容:

ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes -i /path/to/key

这将强制Ansible使用指定的密钥进行连接。

您是否尝试删除要克隆的主机上的密钥。在~/.ssh/known_主机和~/.ssh/authorized_密钥中似乎存在错误的密钥