Why you should use Ansible on WSL (Windows Subsystem for Linux)? Normally you would install Ansible on a separate system and setup your desired configuration there. I already published a blog post on this. Everything works, everything is fine. So, why you also should install ansible on Windows subsystem for Linux? In my case I find it easy to deploy my playbooks in different environments. So, I like to have everything on my laptop and so I can take it with me to the customer side. The other thing for me is, I can write my playbooks and tested directly on my Windows. You can also check my article how to manage your playbooks with Visual Studio Code.
Normally you would install Ansible on a separate system and setup your desired configuration there. I already published a blog post on this. Everything works, everything is fine. So, why you also should install ansible on Windows subsystem for Linux? In my case I find it easy to deploy my playbooks in different environments. So, I like to have everything on my laptop and so I can take it with me to the customer side. The other thing for me is, I can write my playbooks and tested directly on my Windows.
In this post I will show you how to install WSL on Windows and how to set up Ansible to deploy your playbooks there. I have also created a repository on Github, which is containing the scripts for the installation. You will see the Link to Github at the end of the article. But maybe you want to see the steps or want to make it on GUI, you are welcome to read the full post.
Install WSL (Windows Subsystem for Linux)
First of all, we want to do is to install the Windows subsystem for Linux. For further information you can also check the following link from the Microsoft website:
Now I open a PowerShell CLI as an administrator. Here you will paste the following 2 lines to install an activate with their required features.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
I have also attached a screenshot where you can see the execution of the commands and how it looks like if it was successful. After this I would recommend to reboot the system.
Now open the Microsoft store on your Windows desktop and search for “Ubuntu”. You will have multiple choices to install the different versions. I choose the Ubuntu Version 18.04 LTS. Click on the icon to start download.
The installation will start when the download is completed. This may take a few minutes.
Now let´s through the next steps for our installation of ansible on WSL. The installation is not completed and you can find “Ubuntu 18.04 LTS” in your start menu. Click on it to finish the installation.
A new window will open and the installation is starting. Now it’s time to take a coffee, because this would take another few minutes 😉
The next thing we have to do is to create a user for our Linux instance. Enter the username. After that you will be prompted to input a password and retype it.
If everything works fine you will see the message as shown in the following screenshot.
Install Ansible on WSL
In this part I will show you how to install Ansible on our new WSL instance. You will know how have the choice to download the script from my repository ( at the end of the page) and execute the script within the Windows subsystem for Linux CLI.
sudo bash ..\02_install_ansible.sh
If you want to to do the installation step by step, you can execute the following lines in the Windows subsystem for Linux CLI. For some of the commands you have to acknowledge the download with “Yes/Y”.
sudo apt-add-repository ppa:ansible/ansible sudo apt-get update # sudo apt-get install ansible sudo apt install python3-pip sudo pip3 install pywinrm sudo pip3 install pyvmomi sudo pip3 install ansible sudo pip3 install ansible[azure]
Great! We have finished the installation of ansible on WSL. To to run your playbooks you have to navigate to your local disk/ folder, where you playbooks are saved. You can go to your local drive by using “/mnt/C” C= your Driveletter.
Now you can execute your playbooks and have fun solving your requirements with that and automating your environment.
Here you can find the Link to my Github Repository:
Check it out and try it yourself. Feel free to test it on your own and give me a feedback how it works for you. Also check out my other posts. Have fun. Feel free to share my site or post on social media. You can also follow me on Twitter @thomaspreischl