🧰 Configure WSL2 as an Ansible Control Node Runbook

🎯 Purpose

Provision WSL2 (Ubuntu 24.04) on a Windows workstation and configure it as an Ansible control node capable of managing Linux and Windows hosts.


🧩 Prerequisites


πŸ—οΈ Install WSL2

Steps

❗IMPORTANT The ansible user is required for automated configuration.

Optional β€” Change Default User Later

ubuntu config --default-user <username>
wsl --shutdown
wsl -d Ubuntu-24.04

πŸš€ Launch WSL2

Steps


πŸ”„ Update Linux Packages

Steps

Run:

sudo apt update && sudo apt upgrade -y

πŸ” Configure Passwordless Sudo

Steps


🏷️ Set WSL Hostname

Steps


πŸ” Enable External SSH Access

Get WSL IP Address

wsl ip -4 -o addr show eth0 | awk '{print $4}' | cut -d/ -f1

Configure Port Forwarding

Replace wsl_ip_address:

netsh interface portproxy add v4tov4 listenport=22 listenaddress=0.0.0.0 connectport=22 connectaddress=wsl_ip_address

❗IMPORTANT SSH should now be reachable using the Windows host IP.


🌐 Add Host to DNS (Pi‑hole)

Steps

Verify

nslookup dev-0

βš™οΈ Update Ansible Inventory

Add to global_ip_addresses

Edit roles/global/vars/main.yml:

global_ip_addresses:
  dev-0: 192.168.2.120

Add to Inventory Group

Edit inventory/ansible/inventory.ini:

[wsl]
dev-0

πŸ› οΈ Configure WSL Host Using Ansible

❗IMPORTANT Confirm SSH access to the WSL host using the Windows host IP.

Bootstrap Python 3

ansible-playbook -k -i inventory/ansible/inventory.ini playbooks/python/bootstrap_python3.yml -u ansible -l dev-0

Join Active Directory Domain

ansible-playbook -k -i inventory/ansible/inventory.ini playbooks/ad/join_domain.yml -u ansible -l dev-0

⚠️ WARNING This playbook reboots WSL.
After reboot:

Prep Ansible Node

ansible-playbook -k -i inventory/ansible/inventory.ini playbooks/ansible/prep_ansible_node.yml -u ansible -l dev-0

Deploy Ansible

ansible-playbook -k -i inventory/ansible/inventory.ini playbooks/ansible/deploy_ansible.yml -u ansible -l dev-0

πŸ” Verify Ansible Installation

Steps

Expected Output (Example)

ansible [core 2.19.5]
ansible python module location = /opt/python_3.12/lib/python3.12/site-packages/ansible
python version = 3.12.3
...

πŸ“ Working With Repositories

Option A β€” Use Windows Repo

cd /mnt/c/Users/<username>/GitHub/<repo>
git clone https://github.com/<your-repo> ~/projects/<repo>

Benefits


πŸ–₯️ VS Code Integration (WSL)

Steps

VS Code now uses: