Building a Home Lab with Ansible: Automating My Infrastructure
August 18, 2025 đ©đœâđŹ Letisia Pangata'a
IntermediateIn todayâs IT landscape, automation isnât optional, itâs essential. Whether youâre working with cloud-native platforms or managing on-premises servers, tools like Ansible help maintain consistency, reduce errors, and save countless hours.
To deepen my hands-on skills, I built a home lab environment where Ansible automates everything from OS configuration to service deployment. Hereâs a breakdown of how I set it up and what I learned along the way.
Lab Environment Setup
For my lab, I used a mix of:
- Hyper-V / VirtualBox VMs running Ubuntu and Windows Server.
- Ansible control node on Linux.
- Target nodes: a small cluster of Linux and Windows servers for testing.
Inventory file (inventory.ini
):
[linux_servers]
192.168.1.101
192.168.1.102
[windows_servers]
192.168.1.201
Automating with Ansible
Here are some of the automation tasks I implemented:
1. Linux Server Hardening
Applied consistent security configurations across all Linux servers:
---
- name: Secure Linux servers
hosts: linux_servers
become: yes
tasks:
- name: Ensure UFW is installed
apt:
name: ufw
state: present
update_cache: yes
- name: Enable UFW firewall
ufw:
state: enabled
policy: deny
- name: Allow SSH
ufw:
rule: allow
port: 22
proto: tcp
2. Windows Server Automation
Using WinRM, I automated simple tasks like user creation and patching:
---
- name: Configure Windows servers
hosts: windows_servers
tasks:
- name: Create a local user
win_user:
name: labadmin
password: StrongP@ssw0rd!
groups:
- Administrators
3. Service Deployment
Deployed and managed Nginx across all Linux web servers:
---
- name: Install and configure Nginx
hosts: linux_servers
become: yes
tasks:
- name: Install Nginx
apt:
name: nginx
state: present
- name: Start and enable Nginx
service:
name: nginx
state: started
enabled: yes
Key Learnings
- Agentless simplicity: No need to install anything on nodes beyond SSH/WinRM.
- Repeatability: One playbook can configure multiple servers identically.
- Version control matters: Storing playbooks in GitHub made rollbacks and collaboration easy.
- Hybrid focus: Automating both Windows and Linux prepared me for real-world enterprise setups.
Whatâs Next?
My next steps include:
- Integrating Ansible with GitHub Actions to test playbooks in a CI/CD pipeline.
- Expanding my lab with Docker and Kubernetes for containerized workloads.
- Exploring Ansible Galaxy to reuse community roles.
Final Thoughts
Building a home lab with Ansible isnât just an academic exercise, itâs a way to prove your skills in automation, configuration management, and DevOps practices.
Iâve shared some of my playbooks and lab setup on the following GitHub reppository. If youâre learning Ansible, I highly recommend setting up a lab, itâs the best way to gain hands-on experience.
Disclaimer
This project was developed using a combination of publicly available learning resources, reference books, open source projects, and artificial intelligence tools. All efforts have been made to attribute and comply with relevant licenses. Contributions and insights from the broader open source and educational communities are gratefully acknowledged. This software is provided as-is, without warranty of any kind, express or implied. The author assumes no responsibility for any loss, damage, or disruption caused by the use of this code. It is intended for educational and experimental purposes only and may not be suitable for production environments.