Ansible fails to connect from Linux to Windows via SSH

  ansible, ssh, windows

I’ve setup a Windows 10 machine with OpenSSH 8.0.0.1 over choco as discribed here.
I’ve setup a public key and I can now connect from my Linux machine to the Windows.

$ ssh windows-machine echo test
test

Running the following command will result in a error:

$ ansible -m win_command -a "echo test" windows-machine
windows-machine | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "` echo ~/.ansible/tmp `"&& mkdir "` echo ~/.ansible/tmp/ansible-tmp-1619774767.22-15575-62648242524392 `" && echo ansible-tmp-1619774767.22-15575-62648242524392="` echo ~/.ansible/tmp/ansible-tmp-1619774767.22-15575-62648242524392 `" ), exited with result 1", 
    "unreachable": true
}

Those are the files in the current directory:

$ ls
ansible.cfg  hosts

$ cat ansible.cfg 
[defaults]
inventory = ./hosts
ansible_connection = ssh
ansible_shell_type = powershell

$ cat hosts 
windows-machine

I’ve setup the default shell on windows to be powershell. I’ve also tested it with cmd as the default shell, but this didn’t change anything. The error still remains.

This is the ansible version I’m using:

$ ansible --version
ansible 2.9.20
  config file = /home/user/git/ansible-win/ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]

Running the same command with -vvv:

$ ansible -m win_command -vvv -a "echo test" windows-machine

Gives following output which I saved to pastebin

I’ve looked at:

My question is now:

  • Is it at all possible to use Ansible for Windows with SSH?
  • If yes: how?

Source: Windows Questions

LEAVE A COMMENT