Getting Started with Ansible on Windows with WSL
- Windows Subsystem for Linux, or WSL, is a Linux environment in Windows.
- Ansible is an automation tool written in Python that can be used with almost anything that can be reached over SSH. [fix this]
These are the steps I used to get an Ansible control node running in Windows. Ansible control nodes do not natively run in Windows, however there are multiple ways to run a control node in Windows using VMs, Cygwin, or WSL. I use WSL.
These steps are based on my own personal notes for my own future reference. They describe the bare minimum needed to get off the ground with Ansible on Windows.
Installing WSL #
WSL does not come pre-installed on Windows 10 or Windows 11, but can be installed easily with Powershell. Run Powershell as an administrator and run these commands:
wsl --install
This command will install WSL with Ubuntu by default. Other versions of Linux can be installed using the -d flag if needed.
wsl --install -d <distribution name>
Choose a username and password when prompted.
Install Ansible #
Next, we use pip to install Ansible. Using apt will install an older version of Ansible and will cause problems. As of December 2023, pip is the officially supported means of installing Ansible.
Pip is not installed by default on Ubuntu but can be installed using these commands:
sudo apt-get update
sudo apt install pip -y
Ansible can now be installed with pip.
pip install ansible --user ansible
In order to run commands, this directory will have to be added to the path. There are a few ways to do this. The easiest way is to run these commands:
export PATH="/home/<path to directory>/.local/bin:$PATH"
source ~/.bashrc
After running these commands, restart the terminal. We do this by closing the powershell window and opening a new one. The WSL can be re-entered using the name of the Linux distro that was installed.
ubuntu
If everything works, Ansible should be installed and ready to use as a control node.