Ansible Homelab Automation: Configure Multiple Servers with Playbooks

If you manage more than one server or container in your homelab, manual configuration stops scaling quickly. Ansible fixes this by turning your infrastructure into code. You write a playbook once, and it configures every node — packages, users, firewalls, Docker, and system settings — without logging into each machine individually.

Why Ansible for a Homelab

Most configuration tools require agents on every node. Ansible is agentless. It connects over SSH and runs tasks in plain YAML. That means less overhead, easier debugging, and no daemon to maintain on target machines.

For a homelab with Proxmox VMs, LXC containers, and physical servers, Ansible becomes the glue that keeps every node consistent.

Prerequisites

  • A control node (your laptop or a dedicated management VM)
  • Python 3.8+ installed on the control node
  • SSH key-based access to every target node
  • A static inventory of your servers

Install Ansible

On Debian or Ubuntu:

sudo apt update
sudo apt install ansible-core -y

Verify the install:

ansible --version

Create an Inventory

An inventory defines the nodes you want to manage. Create inventory.ini:

[proxmox]
proxmox-node-1 ansible_host=192.168.1.10 ansible_user=root

[truenas]
truenas-node ansible_host=192.168.1.20 ansible_user=root

[firewall]
opnsense ansible_host=192.168.1.1 ansible_user=root

Test connectivity:

ansible all -i inventory.ini -m ping

Write Your First Playbook

Create site.yml:

- name: Homelab baseline setup
  hosts: all
  become: true
  tasks:
    - name: Update apt cache
      apt:
        update_cache: true
        cache_valid_time: 3600

    - name: Install essential packages
      apt:
        name:
          - curl
          - vim
          - htop
          - git
          - ufw
        state: present

    - name: Enable UFW firewall
      ufw:
        state: enabled
        policy: deny incoming
        rule: allow ssh

Run it:

ansible-playbook -i inventory.ini site.yml

Add Role-Based Playbooks

Split tasks into roles for cleaner organization:

  • common: users, SSH keys, timezone, updates
  • docker: install Docker, configure daemon
  • monitoring: install Prometheus Node Exporter
  • backup: install BorgBackup, configure scripts

Then reference roles in your playbook:

- hosts: proxmox
  roles:
    - common
    - docker
    - monitoring

Why This Works Better

Many homelab guides stop at manual setup. That works until you rebuild a node or add a new one. Ansible makes your infrastructure reproducible. A fresh VM can go from zero to fully configured in minutes with a single command.

Final Thoughts

Start small: automate package installs and firewall rules, then expand into Docker stacks and monitoring. Once your Ansible playbooks are in Git, your homelab becomes portable. Rebuilds, clones, and disaster recovery stop being scary and start being routine.

Leave a Comment