手动ssh添加可以工作,但在Ansible中从shell脚本运行时失败。ssh代理转发

手动ssh添加可以工作,但在Ansible中从shell脚本运行时失败。ssh代理转发,ssh,amazon-ec2,ansible,Ssh,Amazon Ec2,Ansible,当我手动[一个接一个地]运行以下命令时,ssh代理转发与远程主机一起工作: eval `ssh-agent -s` ssh-add <>.pem 那么,如何启用ssh代理转发(可能通过ansible本身?)而不在主机中手动输入ssh add命令呢?这就是您想要的 在path中添加pem文件以避免不必要的复杂性 changed: [localhost] => { "changed": true, "cmd": "sh test.sh",

当我手动[一个接一个地]运行以下命令时,ssh代理转发与远程主机一起工作:

eval `ssh-agent -s`
ssh-add <>.pem

那么,如何启用ssh代理转发(可能通过ansible本身?)而不在主机中手动输入ssh add命令呢?

这就是您想要的

在path中添加pem文件以避免不必要的复杂性

   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
}
[ssh_connection]
ssh_args=-o ControlMaster=auto -o ControlPersist=60s -o ControlPath=/tmp/ansible-ssh-%h-%p-%r -o ForwardAgent=yes