# Setting Up an Ansible Control Node Using WSL2

In the previous part of the series, we:

*   Installed VMware Workstation Pro
    
*   Installed Ubuntu and Rocky Linux VMs
    
*   Configured internal networking
    
*   Setup up static IP addresses
    
*   Built a gateway router VM using nftables Now, It's time to level up
    

Instead of manually SSH-ing into each server, we will use **Ansible**.

## What Is Ansible?

Ansible is an open-source automation tool for

*   Provisioning
    
*   Configuration management
    
*   Application deployment
    
*   Orchestration. It follows an **agentless architecture**, meaning nodes do not need any additional software.
    

Ansible works over **SSH(Linux)** or **WinRM(Windows)** and uses **human-readable YAML playbooks** to describe desired system state.

## Why Do We Need Ansible?

So far, we've been managing servers manually using SSH.

```shell
ssh aurora@172.29.10.10
```

This works for 2-3 machines. But in real environments:

*   You might have to manager **10s** or **100s** of servers
    
*   You will need **consistency**
    
*   You will need **repeatability** This is where **Ansible** comes in. With Ansible, You can:
    
*   Run commands on multiple servers at once
    
*   **Enforce** configuration
    
*   Automate provisioning and deployments
    

Consider this scenario:

Imagine you have **50+ VMs**:

*   Some running DBs
    
*   Some running backend service
    
*   Some handling frontend traffic Now a critical patch for OpenSSL or SSH is released.
    

Are you going to SSH into all 50+ machines manually? No.

With Ansible, you can:

*   Run a single command (ad-hoc commands) or playbook
    
*   Ensure systems are updated to the required version
    

> The machine from which Ansible runs is called **Control Node**

> NOTE: This series focuses on building a DevOps Homelab We are using Ansible as an example, so we will not go deep into playbooks and advanced usage here.

## What is WSL2 and Why Use WSL2 Instead of Another VM or Windows itself?

### Why Not Windows?

Ansible is designed for *Linux Environments* While it can run on Windows via python:

*   SSH behavior may be inconsistent
    
*   Many modules assume Linux utilities
    
*   Debugging becomes painful In short: Its not production aligned.
    

### Why not another VM?

This is valid approach. In production, the control node is usually a dedicated Linux Machine. But for a home lab setup:

*   It uses additional CPU/RAM
    
*   Adds management overhead
    
*   Slower Iteration That means: Overkill for a home lab setup
    

### Why not Docker?

Docker is great, but Docker containers are meant to be **ephemeral**. And are not good for control node in early stages of learning DevOps.

*   SSH key management becomes messy
    
*   Container networking adds complexity
    
*   Not ideal for persistent configuration Meaning: Unnecessary abstraction headache
    

### What is WSL2 and Why it's the Best Fit?

WSL2 or Windows Subsystem for Linux 2 is a compatibility layer for running Linux Distributions directly on Windows 10/11 with a real Linux kernel inside a lightweight VM. WSL2 is best fit for our use case because:

*   Native Linux environment
    
*   Fast startup
    
*   Minimal resource consumption than a VM
    
*   Easy Integration with VS Code and most importantly, it can reach our VM via internal network because of the VMware network configuration.
    

Since we enabled *Host-only adapter* while creating internal networks:

*   Windows host is a part of that internal network
    
*   WSL2 shares host network stack That is WSL2 can access the VMs easily
    

## Architecture Diagram

Below gives a high level overview of the architecture of the whole Home lab

![](https://cdn.hashnode.com/uploads/covers/6995a18c50a1f57e3a75a05b/f9a88b0d-057a-4c72-951a-7729edc7ba05.png align="center")

> **Note:** The gateway VM connects both NAT (internet) and internal network, enabling outbound access for all nodes

## Installing WSL2 + Ubuntu

If you haven't installed WSL 2 yet, install it by entering the following command in powershell.

```shell
wsl --install -d ubuntu
```

This will ensure that wsl2 is available and will install Ubuntu. It may ask for UAC and will prompt you to create username and password

To start WSL type:

```shell
wsl
```

First update the packages using

```shell
sudo apt-get update && sudo apt-get upgrade -y
```

## Installing Ansible

Ansible can be installed using `apt`.

Inside WSL run

```shell
sudo apt-get install ansible -y 
```

Verify the installation using

```shell
ansible --version
```

## Configuring SSH (Password-less Authentication)

Ansible uses SSH for communication. For this we will enable Password-less authentication with client. For this:

*   We need to generate SSH-Keys from WSL (control node)
    
*   Transfer generated public key to clients
    

To generate key, enter below command from WSL:

```shell
ssh-keygen -t ed25519 -C 'ansible-control-node'
```

Press `Enter` to accept defaults. Keys will be

```shell
~/.ssh
```

To transfer keys to target nodes, do the following for all the nodes:

```sh
ssh-copy-id <user>@<ip>
```

Replace `<user>` and `<ip>` with username and IP of your nodes.

Example:

```sh
ssh-copy-id aurora@172.29.10.10   # ubuntu VM
ssh-copy-id aurora@172.29.10.20   # rocky VM
```

It will ask for the password. To verify try SSH. If no password is asked, that means setup is successful

## Summary so far

At this point:

*   WSL2 can reach VMs
    
*   Ansible has been installed in WSL2
    
*   Password less authentication has been configured Next we will test ansible.
    

## Creating an Inventory File

We will store all files inside a directory in WSL.

Create a directory `ansible-tests` and cd into it

```shell
mkdir ~/ansible-tests && cd ~/ansible-tests
```

Create inventory file `inventory.ini` with following contents

```shell
[ubuntu]
ubuntu1 ansible_host=172.29.10.10 ansible_user=aurora

[rocky]
rocky1 ansible_host=172.29.10.20 ansible_user=aurora

[all:vars]
ansible_python_interpreter=/usr/bin/python3
```

Replace `aurora` with the username inside the VM.

> TIP: Create a dedicated `ansible` user in real environments

## Testing Ansible

The most basic ansible test is checking connectivity to all hosts Use the ansible's ping module to test the connectivity:

```shell
ansible all -i inventory.ini -m ping
```

the output should be something like :

![](https://cdn.hashnode.com/uploads/covers/6995a18c50a1f57e3a75a05b/08b5e520-58f4-419e-9ca6-5889233d3f75.png align="center")

This confirms that the SSH Works and Inventory is correct and ansible control node is functional.

## Whats Next?

This completes the core DevOps Homelab setup demo. We now have:

*   Multiple Linux servers
    
*   A segmented network
    
*   A gateway router
    
*   An Ansible control node
    

You can now extend your lab with:

*   Kubernetes (K8s)
    
*   Monitoring (Prometheus + Grafana)
    
*   Logging stack (ELK/Loki)
    

I have personally extended this lab further with additional VMs and Planning to implement Monitoring with it.

## Series Roadmap

1.  [Download VMware Workstation Pro](https://bash-sanka1p.hashnode.dev/how-to-download-vmware-workstation-pro-on-windows-step-by-step-guide-2026) ✅
    
2.  [Installation Guide](https://bash-sanka1p.hashnode.dev/how-to-install-vmware-workstation-pro-25h2-on-windows-step-by-step-guide-2026) ✅
    
3.  [Creating Your First VM (Ubuntu Server 22.04)](https://bash-sanka1p.hashnode.dev/install-ubuntu-22-04-server-vmware-workstation-pro-2026) ✅
    
4.  [Installing Rocky Linux on VMware](https://bash-sanka1p.hashnode.dev/install-rocky-linux-9-vmware-workstation-pro-2026) ✅
    
5.  [Setting Up Internal Networks](https://bash-sanka1p.hashnode.dev/how-to-set-up-a-host-only-internal-network-in-vmware-workstation) ✅
    
6.  [Configuring Static IP on Ubuntu and Rocky](https://bash-sanka1p.hashnode.dev/how-to-configure-static-ip-on-ubuntu-and-rocky-linux) ✅
    
7.  [Building a Gateway VM for Multi-VM Lab Architecture](https://blog.sankalpbais.com/linux-gateway-router-vm-ubuntu-nftables) ✅
    
8.  Setting Up an Ansible Control Node Using WSL2 ✅
