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.
I've update ansible to the latest version with:
pip3 install --user --upgrade pip
pip3 install --user ansible
hash -r
Now I got:
$ ansible --version
ansible 2.10.8
config file = /home/user/git/ansible-win/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/user/.local/lib/python3.6/site-packages/ansible
executable location = /home/user/.local/bin/ansible
python version = 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.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
The crucial part beeing: <windows-machine> (1, '', '/bin/sh : Die Benennung "/bin/sh" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines
ausfx81hrbaren Programms erkannt.
I've looked at:
My question is now:
- Is it at all possible to use Ansible for Windows with SSH?
- If yes: how?
See Question&Answers more detail:
os