2017-07-25 83 views
0

我已經看過類似的問題,但還沒有找到答案。回購不會克隆,「權限被拒絕」,使用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'。 –

回答

3

從您的詳細輸出我看到:

  • 第一,使用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

0

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