在远程主机上运行 Ansible ping 失败,并出现未知的 SSH 错误

在远程主机上运行 Ansible ping 失败,并出现未知的 SSH 错误

我尝试执行 Ansible ping ansible all -m ping --ask-pass,但出现 SSH 失败。由于调试日志相当广泛,我将下面的引文缩减到我认为问题发生的位置。在日志的前面,我能够连接到远程主机(无头 RHEL5 VM),但实际执行“ping”时,它会失败并出现以下错误。

debug1: Entering interactive session.
debug2: set_control_persist_exit_time: schedule exit in 60 seconds
debug1: multiplexing control connection
debug2: fd 4 setting O_NONBLOCK
debug3: fd 5 is O_NONBLOCK
debug3: fd 5 is O_NONBLOCK
debug1: channel 1: new [mux-control]
debug3: channel_post_mux_listener: new mux channel 1 fd 5
debug3: mux_master_read_cb: channel 1: hello sent
debug2: set_control_persist_exit_time: cancel scheduled exit
debug3: mux_master_read_cb: channel 1 packet type 0x00000001 len 4
debug2: process_mux_master_hello: channel 1 slave version 4
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_master_read_cb: channel 1 packet type 0x10000004 len 4
debug2: process_mux_alive_check: channel 1: alive check
debug3: mux_client_request_alive: done pid = 9664
debug3: mux_master_read_cb: channel 1 packet type 0x10000002 len 264
debug2: process_mux_new_session: channel 1: request tty 1, X 0, agent 0, subsys 0, term "xterm", cmd "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1392125626.39-45498424175459 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1392125626.39-45498424175459 && echo $HOME/.ansible/tmp/ansible-tmp-1392125626.39-45498424175459'", env 0
debug3: mux_client_request_session: session request sent
mm_receive_fd: no message header
process_mux_new_session: failed to receive fd 0 from slave
debug1: channel 1: mux_rcb failed
debug2: channel 1: zombie
debug2: channel 1: gc: notify user
debug3: mux_master_control_cleanup_cb: entering for channel 1
debug2: channel 1: gc: user detached
debug2: channel 1: zombie
debug2: channel 1: garbage collecting
debug1: channel 1: free: mux-control, nchannels 2
debug3: channel 1: status: The following connections are open:

我通过常规 SSH 连接到主机,然后检查 xterm 是否在远程机器上运行以及是否已安装。它运行但失败并出现以下错误:

xterm Xt error: Can't open display:
xterm:  DISPLAY is not set

我的直觉是 ssh 连接后尝试运行命令,但由于 xterm 崩溃而无法运行。我一直在寻找更改要使用的终端的方法,但在文档中找不到任何内容。非常感谢任何意见或建议。

答案1

截至撰写本文时,在 Windows 上的 Cygwin 中运行 Ansible 时出现了一些奇怪的问题。不确定是什么问题,但我无法修复。我切换到 Linux VM,一切开始正常工作。

答案2

我花了大约 2 个小时在 cygin 上搜索奇怪的错误,并按照以下设置进行了操作:

cat /etc/ansible/ansible.cfg
[defaults]
host_key_checking = False

可能对安全不利......,此外:

 cat /etc/ansible/hosts
 [dbservers]
 56.77.50.151   ansible_ssh_port=22     ansible_ssh_user=ssh_user

核实:

ansible -vvvv all -a "/bin/echo hello"

我必须确保公私钥认证配置正确

cat id_rsa.pub >> ~/.ssh/authorized_keys
cat ~/.ssh/authorized_keys
chmod 0600  ~/.ssh/authorized_keys
ls -al ~/.ssh/authorized_keys
rm -fv ~/id_rsa.pub

我怀疑cygwin 上的组和用户配置:和 chown -v local_pc_user:local_pc_user ~/.ssh/id_rsa.pub

最后输出为:

    <56.77.50.151> ESTABLISH CONNECTION FOR USER: ssh_user
    <56.77.50.151> REMOTE_MODULE command /bin/echo hello
    <56.77.50.151> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o',
    'ControlPath=/home/local_pc_user/.ansible/cp/ansible-ssh-%h-%p-%r',
    '-o', 'StrictHostKeyChecking=no', '-o', 
    'Port=22', '-o', 'KbdInteractiveAuthentication=no',
    '-o', 'PreferredAuthentications=gssapi-with-mic,
    gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ssh_user', '-o', 'ConnectTimeout=10',
    '56.77.50.151', "/bin/sh -c 'mkdir -p
    $HOME/.ansible/tmp/ansible-tmp-1397676665.28-153356552524280 &&
    chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397676665.28-153356552524280 &&
    echo $HOME/.ansible/tmp/ansible-tmp-1397676665.28-153356552524280'"]
    <56.77.50.151> PUT /tmp/tmprELaVU TO /export/home/ssh_user/.ansible/tmp/ansible-tmp-1397676665.28-153356552524280/command
    <56.77.50.151> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto',
    '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/local_pc_user/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'StrictHostKeyChecking=no', '-o', 'Port=22',
    '-o', 'KbdInteractiveAuthentication=no', '-o', 
    'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ssh_user', '-o', 'ConnectTimeout=10'
    , '56.77.50.151', "/bin/sh -c '/usr/bin/python 
    /export/home/ssh_user/.ansible/tmp/ansible-tmp-1397676665.28-153356552524280/command; 
    rm -rf /export/home/ssh_user/.ansible/tmp/ansible-tmp-1397676665.28-153356552524280/ 
    >/dev/null 2>&1'"]
    56.77.50.151 | success | rc=0 >>
    hello

答案3

这种行为是在 Ansible 更新后开始的。在旧版 Ansible 中我没有遇到任何问题。问题似乎确实出在 xterm 上。为什么 Ansible 需要运行 xterm?我将其归类为 Ansible 中的一个错误。

无论如何,我通过添加以下内容解决了 Cygwin 中的该问题~/.ssh/config

ForwardX11 是

相关内容