Ansible部署时Git克隆遇公钥权限拒绝问题求助
Git拉取代码Permission Denied (publickey)错误求助
执行Git仓库拉取操作时触发经典权限错误:
Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
已做排查动作:
- 私钥
tp10_deploy_key已正确复制到远程机器/root/.ssh目录,匹配的公钥已配置为对应仓库的部署密钥,但手动克隆同样报错 - 尝试将GitHub上的
tp_deploy_key公钥从仓库专属部署密钥改为全局认证密钥,无论Ansible还是手动操作依旧报错 - 本地与远程服务器通信正常,其他Ansible部署命令均可执行
- 测试过开启/关闭
ForwardAgent配置,结果无变化
Ansible任务代码
- name: 'Repo does not exist' block: - name: Copy the repo to the remote server. git: repo: "{{ git_repo_url }}" version: "{{ git_repo_version }}" dest: "{{ drupal_core_path }}" separate_git_dir: "{{ git_bare_dir }}" force: yes single_branch: yes depth: 1 accept_newhostkey: yes key_file: "{{ github_deploy_key }}" register: code_uploaded when: - not repo_dir.stat.exists
调试信息
"changed": false, "cmd": "/usr/bin/git ls-remote git@github.com:xxx/xxx.git -h refs/heads/master", "invocation": { "module_args": { "accept_hostkey": false, "accept_newhostkey": true, "archive": null, "archive_prefix": null, "bare": false, "clone": true, "depth": 1, "dest": "/var/www", "executable": null, "force": true, "gpg_whitelist": [], "key_file": "/root/.ssh/tp10_deploy_key", "recursive": true, "reference": null, "refspec": null, "remote": "origin", "repo": "git@github.com:xxx/xxx.git", "separate_git_dir": "/root/tp10", "single_branch": true, "ssh_opts": null, "track_submodules": false, "umask": null, "update": true, "verify_commit": false, "version": "master" } },
ansible.cfg配置
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ForwardAgent=yes
补充环境信息:
- 部署目标:DigitalOcean Ubuntu 20.04 droplet
- 本地开发环境:Ubuntu 20.04虚拟机
内容的提问来源于stack exchange,提问作者Adaddinsane
相关产品推荐
相关产品推荐

