Great! I was able to connect to my windows host after following those steps.
However, I had to solve two more issues before I was able to run ansible playbooks against both, WSL and windows host:
1. Define connection for WSL
Windows host uses ansible_connection=winrm
, but for WSL needs a different connection, I've set ansible_connection=local
.
2. Avoid connection var being overriden
The ansible_connection
var is overridden. This is because the var name and the host name is the same. This means that you can either run a playbook for WSL or for Windows host but not against both, as they need different connection.
To fix that you can either set hash-behaviour, or set two different host names for localhost under your WSL, /etc/hosts
. I've done the second one:
127.0.0.1 wsl.local
127.0.0.1 windows.local
My /etc/ansible/hosts
:
[wsl]
wsl.local
[wsl:vars]
ansible_connection=local
[windows]
windows.local
[windows:vars]
ansible_port=5985
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_user=<<ansible_user>>
ansible_password=<<ansible_password>>
Now I can run an ansible_playbook with tasks running against both, my windows host and my WSL. Here for more details on configuration.