【发布时间】:2017-03-30 01:39:17
【问题描述】:
当我 [一个接一个地] 手动运行以下命令时,ssh-agent 转发适用于远程主机:
eval `ssh-agent -s`
ssh-add <>.pem
但是,当我将它们捆绑在一个 shell 脚本中并作为 Ansible 运行时,ssh 转发不起作用。像这样:
changed: [localhost] => {
"changed": true,
"cmd": "sh test.sh",
"delta": "0:00:00.008763",
"end": "2017-03-29 12:10:12.337557",
"invocation": {
"module_args": {
"_raw_params": "sh test.sh",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"rc": 0,
"start": "2017-03-29 12:10:12.328794",
"stderr": "Identity added: <>.pem (<>.pem)",
"stdout": "Agent pid <>",
"stdout_lines": [
"Agent pid <>"
],
"warnings": []
}
它返回同样的错误:
fatal: [<>]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey).\r\n",
"unreachable": true
}
我的 ansible.cfg 看起来像这样:
[ssh_connection]
ssh_args=-o ControlMaster=auto -o ControlPersist=60s -o ControlPath=/tmp/ansible-ssh-%h-%p-%r -o ForwardAgent=yes
那么,如何在不手动输入主机中的 ssh-add 命令的情况下启用 ssh-agent 转发(可能通过 ansible 本身?)?
【问题讨论】:
标签: ssh amazon-ec2 ansible