windows - Ansible无法通过SSH连接到Windows节点

标签 windows powershell ssh ansible openssh

我正在尝试通过Ansible配置运行OpenSSH(https://github.com/PowerShell/Win32-OpenSSH)的Windows节点。虽然正常的SSH连接有效,但Ansible似乎无法连接到该节点。

普通SSH连接:

sysadmin@MY_LINUX_SERVER:~/ansible$ ssh administrator@MY_WINDOWS_HOST -vvvv
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to MY_WINDOWS_HOST [A.B.C.D] port 22.
debug1: Connection established.
debug1: identity file /home/sysadmin/.ssh/id_rsa type -1
debug1: identity file /home/sysadmin/.ssh/id_rsa-cert type -1
debug1: identity file /home/sysadmin/.ssh/id_dsa type -1
debug1: identity file /home/sysadmin/.ssh/id_dsa-cert type -1
debug1: identity file /home/sysadmin/.ssh/id_ecdsa type -1
debug1: identity file /home/sysadmin/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/sysadmin/.ssh/id_ed25519 type -1
debug1: identity file /home/sysadmin/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.1
debug1: match: OpenSSH_7.1 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "MY_WINDOWS_HOST" from file "/home/sysadmin/.ssh/known_hosts"
debug3: load_hostkeys: found key type ECDSA in file /home/sysadmin/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-ed25519,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
debug2: kex_parse_kexinit: ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: setup hmac-sha1-etm@openssh.com
debug1: kex: server->client aes128-ctr hmac-sha1-etm@openssh.com none
debug2: mac_setup: setup hmac-sha1-etm@openssh.com
debug1: kex: client->server aes128-ctr hmac-sha1-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 1b:1b:43:b9:74:34:48:0b:06:9d:11:9c:9b:51:56:61
debug3: load_hostkeys: loading entries for host "MY_WINDOWS_HOST" from file "/home/sysadmin/.ssh/known_hosts"
debug3: load_hostkeys: found key type ECDSA in file /home/sysadmin/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: load_hostkeys: loading entries for host "A.B.C.D" from file "/home/sysadmin/.ssh/known_hosts"
debug3: load_hostkeys: found key type ECDSA in file /home/sysadmin/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug1: Host 'MY_WINDOWS_HOST' is known and matches the ECDSA host key.
debug1: Found key in /home/sysadmin/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/sysadmin/.ssh/id_rsa ((nil)),
debug2: key: /home/sysadmin/.ssh/id_dsa ((nil)),
debug2: key: /home/sysadmin/.ssh/id_ecdsa ((nil)),
debug2: key: /home/sysadmin/.ssh/id_ed25519 ((nil)),
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: start over, passed a different list publickey,password,keyboard-interactive
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/sysadmin/.ssh/id_rsa
debug3: no such identity: /home/sysadmin/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /home/sysadmin/.ssh/id_dsa
debug3: no such identity: /home/sysadmin/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/sysadmin/.ssh/id_ecdsa
debug3: no such identity: /home/sysadmin/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/sysadmin/.ssh/id_ed25519
debug3: no such identity: /home/sysadmin/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: userauth_kbdint: disable: no info_req_seen
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred:
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
administrator@MY_WINDOWS_HOST's password:
debug3: packet_send2: adding 48 (len 64 padlen 16 extra_pad 64)
debug2: we sent a password packet, wait for reply
debug1: Authentication succeeded (password).
Authenticated to MY_WINDOWS_HOST ([A.B.C.D]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug1: Sending environment.
debug3: Ignored env XDG_SESSION_ID
debug3: Ignored env TERM
debug3: Ignored env SHELL
debug3: Ignored env SSH_CLIENT
debug3: Ignored env OLDPWD
debug3: Ignored env SSH_TTY
debug3: Ignored env USER
debug3: Ignored env LS_COLORS
debug3: Ignored env MAIL
debug3: Ignored env PATH
debug3: Ignored env PWD
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug3: Ignored env SHLVL
debug3: Ignored env HOME
debug3: Ignored env LOGNAME
debug3: Ignored env SSH_CONNECTION
debug3: Ignored env LESSOPEN
debug3: Ignored env XDG_RUNTIME_DIR
debug3: Ignored env LESSCLOSE
debug3: Ignored env _
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

administrator@MY_WINDOWS_HOST C:\Users\Administrator>exit
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug2: channel 0: rcvd eow
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)

Connection to MY_WINDOWS_HOST closed.
Transferred: sent 3024, received 2792 bytes, in 166.9 seconds
Bytes per second: sent 18.1, received 16.7
debug1: Exit status 0
sysadmin@MY_LINUX_SERVER:~/ansible$

尝试与Ansible建立联系:
sysadmin@MY_LINUX_SERVER:~/ansible$ ansible -i staging iis -m win_ping -vvvv
<MY_WINDOWS_HOST> ESTABLISH CONNECTION FOR USER: Administrator
<MY_WINDOWS_HOST> REMOTE_MODULE win_ping
<MY_WINDOWS_HOST> EXEC sshpass -d6 ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/sysadmin/.ansible/cp/ansible-ssh-%h-%p-%r" -o Port=22 -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o User=Administrator -o ConnectTimeout=10 MY_WINDOWS_HOST /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445861196.89-92060959437896 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1445861196.89-92060959437896 && echo $HOME/.ansible/tmp/ansible-tmp-1445861196.89-92060959437896'
MY_WINDOWS_HOST | FAILED => SSH Error: Failed to connect to new control master
    while connecting to A.B.C.D:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
sysadmin@MY_LINUX_SERVER:~/ansible$

有什么线索为什么不能通过Ansible进行连接?

最佳答案

我相信Microsoft的家伙们仍然没有解决文件描述符传递问题,因此ControlMaster函数可能无法正常工作,即使它没有提前宣布。如评论所建议禁用它,应该可以解决您的问题。您还可以在/etc/ansible/ansible.cfg中使用ansible配置:

ssh_args = -o ControlMaster=no

关于windows - Ansible无法通过SSH连接到Windows节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33345833/

相关文章:

java - JSch中的 'shell' channel 和 'exec' channel 有什么区别

windows - 有没有我可以在 Windows 上安装的 kdevelop 版本?

powershell - 检查处理器体系结构并继续执行if语句

powershell - 使用DisplayNames从文本文件获取SamAccountName

amazon-web-services - 更改 ec2 实例的 key 对

GIT 并行克隆所有存储库,即克隆所有存储库的总时间接近于最大存储库 : fatal: index-pack failed 所需的时间

c++ - 如何更改 QProgressBar 的状态?

c# - "Console", "cmd.exe", "shell"之间的区别?

c - 执行从 Windows 服务捕获屏幕截图的程序

powershell - imagemagick 中 STDIN/STDOUT 的正确语法