我有一本剧本,我试图从私人存储库(GIT)克隆到服务器。
我已经设置了 ssh 转发,当我 ssh 进入服务器并尝试从同一存储库手动克隆时,它成功工作。但是,当我使用 ansible 将存储库克隆到服务器时,它失败并显示“权限被拒绝公钥”。
这是我的剧本deploy.yml
:
---
- hosts: webservers
remote_user: root
tasks:
- name: Setup Git repo
git: repo={{ git_repo }}
dest={{ app_dir }}
accept_hostkey=yes
这就是我的ansible.cfg
looks:
[ssh_args]
ssh_args = -o FowardAgent=yes
我还能够执行我的剧本中的所有其他任务(操作系统操作、安装)。
我努力了:
- Specifying sshAgentForwarding flag in
ansible.cfg
on the server (ansible.cfg in same dir as playbook) using:
ssh_args = -o ForwardingAgent=是
- used
become: false
执行 git 克隆
-
running ansible -i devops/hosts webservers -a "ssh -T [email protected] /cdn-cgi/l/email-protection"
返回:
an_ip_address | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}
这是我用来运行剧本的命令:ansible-playbook devops/deploy.yml -i devops/hosts -vvvv
这是我收到的错误消息:
fatal: [162.243.243.13]: FAILED! => {"changed": false, "cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "invocation": {"module_args": {"accept_hostkey": true, "bare": false, "clone":
true, "depth": null, "dest": "/var/www/aWebsite", "executable": null, "force": false, "key_file": null, "recursive": true, "reference": null, "refspec": null, "remote": "origin", "repo": "[email protected] /cdn-cgi/l/email-protection:aUser/aRepo.git", "ssh_opts": null, "track_submodules": false, "update": true, "verify_commit": false, "version": "HEAD"}, "module_name": "git"}, "msg": "Permission denied (publickey).\r\nfatal: Could not r$ad from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "Permission denied (publickey).\r\nfatal: Could not read from remote r$pository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stdout": "", "stdout_lines": []}