回购不会克隆,“权限被拒绝”,使用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]
从您的详细输出我看到:
- 第一,使用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
参数。
什么是'become_user:“{{deploy_user}}”'for?它与你的远程用户有什么不同(你使用ssh连接)?在这种情况下,您的ssh代理套接字可能在_becoming_不同的用户之后无法访问。 –
我'admin'和'deploy'用户,管理员用户可以sudo,最'deploy'用户不能。我试图删除这条线,但没有效果。我可以以任何用户身份ssh并克隆回购。 – Kris
你调用与'become'选项任务(后'ssh命令的输出-vvv'这个任务执行)?当你登录的任一用户SSH代理的作品,但在登录后停止工作,当你'sudo'。 –