【问题标题】:Manual ssh-add works but fails when run from shell script in Ansible. ssh-agent forwarding手动 ssh-add 有效,但在 Ansible 中从 shell 脚本运行时失败。 ssh-代理转发
【发布时间】: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


    【解决方案1】:

    这就是你要找的 http://docs.ansible.com/ansible/intro_configuration.html#private-key-file

    在 path 中添加 pem 文件以避免不必要的麻烦。

    【讨论】:

      猜你喜欢
      • 2021-03-12
      • 1970-01-01
      • 2017-04-28
      • 2015-02-21
      • 1970-01-01
      • 2022-01-12
      • 2014-07-30
      • 2017-01-13
      • 2011-10-29
      相关资源
      最近更新 更多