1

I am trying to configure a Windows node running OpenSSH (https://github.com/PowerShell/Win32-OpenSSH) via Ansible. While normal SSH connection works, Ansible seems to fail to connect to the node.

Normal SSH connection:

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$

Attempt to connect with 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$

Any clue why the connection is not working via Ansible?

Tal Auslander
  • 97
  • 1
  • 8
  • What happens if you try `export ANSIBLE_SSH_ARGS='-o ControlMaster=no'` or setting `ControlMaster=no` in ansible.cfg? – ydaetskcoR Oct 26 '15 at 13:15
  • Thanks, seems like I'm getting a different error now: [http://pastebin.com/hWJXnych](http://pastebin.com/hWJXnych) – Tal Auslander Oct 26 '15 at 13:45

1 Answers1

2

I believe the guys from Microsoft still didn't solve the file-descriptor passing issue so ControlMaster function is probably not working, even though it is not announced in advance. Disabling it as the comment proposes, should solve your issue. You can use also ansible config in /etc/ansible/ansible.cfg:

ssh_args = -o ControlMaster=no
Jakuje
  • 24,773
  • 12
  • 69
  • 75
  • Thanks, followed previous comment and tried that. Seems like I'm getting a new error: [http://pastebin.com/hWJXnych](http://pastebin.com/hWJXnych) – Tal Auslander Oct 26 '15 at 13:50
  • Now you should check the server log (not sure where you can find it Windows), why was your password rejected. Are you sure the password is correct? – Jakuje Oct 26 '15 at 13:53
  • Yes, the password is correct. Checked the logs, it says: `2092 06:59:36 719 Accepted password for Administrator from IP port 40174 ssh2 2092 06:59:36 719 fatal: ssh_dispatch_run_fatal: Connection to IP: incomplete message` – Tal Auslander Oct 26 '15 at 14:00
  • This message is not much verbose, but I think you can blame the command that is executed by `ssh`: `/bin/sh -c ` is probably not able to execute on Windows host. You can try from commandline if this simplified command will work you: `ssh -C -tt -vvv -o ControlMaster=no -o Port=22 -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o User=Administrator -o ConnectTimeout=10 MY_WINDOWS_HOST /bin/sh -c "echo hello"` – Jakuje Oct 26 '15 at 14:10
  • Makes sense. The command fails with the same error in the windows sshd log, and this is the execution log: [http://pastebin.com/Qm3pgNHe](http://pastebin.com/Qm3pgNHe) – Tal Auslander Oct 26 '15 at 14:24
  • You can try to modify the bash using `executable` option is config, but not sure what to put there instead. – Jakuje Oct 26 '15 at 14:26
  • I tried `C:\Windows\System32\cmd.exe` and `C:\Windows\System32\\WindowsPowershell\v1.0\powershell.exe` and they both seem to fail with the same error – Tal Auslander Oct 26 '15 at 14:36
  • This is probably material for bug report and some more intense debugging, if you can run shell without command and can't run command. From this output I can't read and help more. – Jakuje Oct 26 '15 at 14:39
  • Thanks. I did remove the -C parameter from the ssh command and it seems to connect (although still not running the command correctly). Not sure if its possible to configure Ansible to not use the -C parameter. – Tal Auslander Oct 26 '15 at 14:41
  • Oh. I though about this switch, but it felt unlike it can make difference. I don't see any switch to disable compression in ansible, but you can try to use `ssh_args -o Compression no`, but I am afraid that the `-C` switch takes precedence over the options like this. – Jakuje Oct 26 '15 at 14:46
  • Indeed I managed to get it to work, had to remove the -C parameter from the ssh command, and to call `cmd.exe /c "echo hi"` [http://pastebin.com/4tRryt9e](http://pastebin.com/4tRryt9e) So, I need both to remove the -C parameter from ansible ssh call, both change the executable and both change the `-c` passed to bash to `/c` – Tal Auslander Oct 26 '15 at 14:48
  • Great. One step closer. This will probably require some change in ansible code. And since it is open source, this can't be so hard :) – Jakuje Oct 26 '15 at 14:51
  • Thanks, apparently there's already a PR on Ansible for the compression flag, so I'll provide them with the info. [https://github.com/ansible/ansible/pull/10951](https://github.com/ansible/ansible/pull/10951) – Tal Auslander Oct 26 '15 at 15:03