I have installed Ansible in the WSL (Windows Subsystem for Linux) within my Windows 10 workstation.
My goal is configure both, WSL, and the Windows 10 itself.
I'm able to run playbooks against localhost, which connect and configures via SSH the WSL.
However I am not sure Ansible can run playbooks against the Windows host to be able to setup Windows itself (e.g. install packages using Chocolatey)
Is that even possible? Or Ansible can only setup a windows node when is installed in a different Linux machine?
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:
Windows host uses ansible_connection=winrm
, but for WSL needs a different connection, I've set ansible_connection=local
.
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.
Yes, it's possible.
$ apt install python-pip
$ pip install pywinrm
$ pip install xmltodict
Enable-PSRemoting -SkipNetworkProfileCheck
but I dont suggest doing that.Enable-PSRemoting
running it in the PowerShell in Windows. Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true
Set-Item -Path WSMan:\localhost\Service\AllowUnencrypted -Value $true
ansible_port: 5985
ansible_connection: winrm
ansible_winrm_transport: basic
ansible_user=your_win_user
and ansible_password=your_win_user_pass
or hardcode them in the previous vars. I use this setup to provision my machine from WSL. You can take a look here. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With