回购不会克隆,“权限被拒绝”,使用git模块

问题描述:

我已经看过类似的问题,但还没有找到答案。回购不会克隆,“权限被拒绝”,使用git模块

我可以通过SSH连接到服务器(Ubuntu 16.04)并手动克隆我的git仓库。这让我相信它不是一个SSHForwardAgent问题。

的错误是非常典型:

"Cloning into bare repository '/home/deploy/apps/MYPROJECT/production/cached-copy'...", 
"Permission denied (publickey).", 
"fatal: Could not read from remote repository.", 

ansible.cnf:

[ssh_connection] 
ssh_args = -o ForwardAgent=yes 

的作用是这样的:

- name: Update the bare Git repository 
    become_user: "{{ deploy_user }}" 
    git: 
    repo: "[email protected]:MYUSER/MYPROJECT.git" 
    dest: "{{ deploy_to }}/cached-copy" 
    version: "{{ branch }}" 
    bare: yes 
    update: yes 
    accept_hostkey: yes 
    ssh_opts: "-o StrictHostKeyChecking=no -o ForwardAgent=yes" 

从Ansible详细输出是:

"changed": false, 
"cmd": "/usr/bin/git clone --bare '' /home/deploy/apps/MYPROJECT/production/cached-copy", 
"failed": true, 
"invocation": { 
"module_args": { 
"accept_hostkey": true, 
"bare": true, 
"clone": true, 
"depth": null, 
"dest": "/home/deploy/apps/MYPROJECT/production/cached-copy", 
"executable": null, 
"force": false, 
"key_file": null, 
"recursive": true, 
"reference": null, 
"refspec": null, 
"remote": "origin", 
"repo": "[email protected]:MYUSER/MYPROJECT.git", 
"ssh_opts": "-o StrictHostKeyChecking=no -o ForwardAgent=yes", 
"track_submodules": false, 
"umask": null, 
"update": true, 
"verify_commit": false, 
"version": "master" 

MYUSER和MYPROJECT的使用是收回此类信息。

有一点看起来可疑是cmd它不包含回购网址,这是正常的吗?

如果我将-o ForwardAgent=yes更改为-A,则会得到不同的错误:Timeout (12s) waiting for privilege escalation prompt

另外我知道AgentForward正在工作,因为如果我ssh进入服务器并做ssh -T [email protected]我得到预期的“您已成功验证,但GitHub不提供shell访问。”。

请注意我不想在服务器上安装私钥。

更新:下面是详细输出的要点:https://gist.github.com/krisleech/8bfbf817c237258a672b3b3393fea8dd

在另一方面,这似乎很好地工作:

- name: "Test github" 
    command: ssh -T [email protected] 
+0

什么是'become_user:“{{deploy_user}}”'for?它与你的远程用户有什么不同(你使用ssh连接)?在这种情况下,您的ssh代理套接字可能在_becoming_不同的用户之后无法访问。 –

+0

我'admin'和'deploy'用户,管理员用户可以sudo,最'deploy'用户不能。我试图删除这条线,但没有效果。我可以以任何用户身份ssh并克隆回购。 – Kris

+0

你调用与'become'选项任务(后'ssh命令的输出-vvv'这个任务执行)?当你登录的任一用户SSH代理的作品,但在登录后停止工作,当你'sudo'。 –

从您的详细输出我看到:

  • 第一,使用ssh远程盒admin用户和ForwardAgent=yes
  • 那么,你须藤为deploy运行Ansible任务(GIT模块)

这是我在评论中描述的场景,在执行sudo(通常的设置)时,您实际上禁用了ssh代理访问。

为了使这项工作,您可能需要直接与deploy用户SSH(而不是与admin->deploy),或在您的目的地箱设置sudo允许饲养环境变量,见this answer了解详情。

Add Defaults env_keep+=SSH_AUTH_SOCK to sudoers

repo参数协议丢失。从ansible-doc

# Example git checkout from Ansible Playbooks 
    - git: 
    repo: git://foosball.example.org/path/to/repo.git 
    dest: /srv/checkout 

尝试增加git:ssh:repo参数。

+0

我都尝试'SSH://'和和'https://开头',不幸的是,同样的错误。而'git://'不是github的选项。无论如何,好的。 – Kris

+0

还通过'http://'需要某种象征的,因为我已经2FA开启。 – Kris

+0

通过,如果我做'混帐混帐克隆的方式://[email protected]:krisleech/mos.git'我得到'致命的服务器上:无法从远程repository.'读取。 – Kris