我正在使用 Ansible 1.5.3 和 Git 以及 ssh 代理转发(https://help.github.com/articles/using-ssh-agent-forwarding https://help.github.com/articles/using-ssh-agent-forwarding)。我可以登录到我使用 Ansible 管理的服务器并测试我与 git 的连接是否配置正确:
ubuntu@test:~$ ssh -T [email protected] /cdn-cgi/l/email-protection
Hi gituser! You've successfully authenticated, but GitHub does not provide shell access.
我还可以使用此帐户克隆和更新我的一个存储库,这样我的 git 配置看起来不错,并且当我直接通过 ssh 登录到我的服务器时使用 ssh 转发。
问题:当我尝试使用 Ansible 命令模块进行上面所示的相同测试时。它失败并显示“权限被拒绝”。 Ansible 输出的一部分(带有详细日志记录)如下所示:
failed: [xxx.xxxxx.com] => {"changed": true, "cmd": ["ssh", "-T", "[email protected] /cdn-cgi/l/email-protection"], "delta": "0:00:00.585481", "end": "2014-06-09 14:11:37.410907", "rc": 255, "start": "2014-06-09 14:11:36.825426"}
stderr: Permission denied (publickey).
这是运行此命令的简单剧本:
- hosts: webservers
sudo: yes
remote_user: ubuntu
tasks:
- name: Test that git ssh connection is working.
command: ssh -T [email protected] /cdn-cgi/l/email-protection
问题:为什么当我通过 ssh 手动登录并运行命令时一切正常,但当通过 Ansible 以同一用户身份运行相同命令时却失败?
如果没有人比我更胜一筹,我会尽快发布答案。尽管我使用 git 来演示该问题,但任何依赖 ssh 代理转发的模块都可能会出现该问题。它不是 Ansible 特有的,但我怀疑很多人都会在这种情况下首先遇到这个问题。