Skip to content

khangvum/homelab-ansible-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Homelab Configuration Automation with Ansible

A homelab configuration automation solution powered by Ansible, containerized with Docker. This setup simplifies Windows and standalone ESXi systems management by leveraging Ansible's idempotent and declarative configuration approach, streamlining Infrastructure as Code (IaC) principles for Windows and VMware environments.

Features

  • Agentless architecture powered by Ansible, utilizing SSH.
  • Docker-based controller for environment consistency across platforms.
  • Modular role-based configuration and tag-based execution for targeted provisioning.
  • Centralized variable management using external YAML files.

Setup Diagram

flowchart LR
    %% 1. KVM-SRV01
    %% - Host
    SRV01_SPECS[("`**Model:** Precision 5820 Tower
        **CPU:** Intel Xeon W-2155 (10 cores - 20 threads)
        **RAM:** 128GB (4 x 32GB ECC 2666MHz)
        **Storage:**
        • 2 x 1TB NVMe SSD (1 OS & 1 VMs)
        • 2 × 4TB HDD (RSTe RAID 1)
        **OS:** Windows Server 2025`")] -- specs --- SRV01[KVM-SRV01]
    
    %% - VMs
    SRV01 --> DB01[KVM-DB01] -- specs --- DB01_SPECS[("`**CPU:** 4 vCPU
                                                        **RAM:** 16GB
                                                        **Storage:** 200GB
                                                        **OS:** Windows Server 2025
                                                        **Role:** SQL Server`")]
    SRV01 --> DC01[KVM-DC01] -- specs --- DC01_SPECS[("`**CPU:** 2 vCPU
                                                        **RAM:** 8GB
                                                        **Storage:** 100GB
                                                        **OS:** Windows Server 2025
                                                        **Role:** Domain Controller`")]
    SRV01 --> WEB01[KVM-WEB01] -- specs --- WEB01_SPECS[("`**CPU:** 2 vCPU
                                                            **RAM:** 8GB
                                                            **Storage:** 100GB
                                                            **OS:** Windows Server 2025
                                                            **Role:** IIS Web Server`")]
    SRV01 --> WRK01[KVM-WRK01] -- specs --- WRK01_SPECS[("`**CPU:** 4 vCPU
                                                            **RAM:** 8GB
                                                            **Storage:** 100GB
                                                            **OS:** Windows 11 Pro`")]
    SRV01 --> WRK02[KVM-WRK02] -- specs --- WRK02_SPECS[("`**CPU:** 4 vCPU
                                                            **RAM:** 8GB
                                                            **Storage:** 100GB
                                                            **OS:** Windows 10 Pro`")]

    

    %% 2. KVM-SRV02
    %% - Host
    SRV02_SPECS[("`**Model:** Precision 5820 Tower
        **CPU:** Intel Xeon W-2123 (4 cores - 8 threads)
        **RAM:** 32GB (2 x 16GB ECC 2666MHz)
        **Storage:**
        • 1 x 1TB NVMe SSD (OS)
        • 1 x 1TB SATA SSD (VMs)
        **OS:** VMware ESXi 8.0 Update 3e`")] -- specs --- SRV02[KVM-SRV02]

    %% - VMs
    SRV02 --> DC02[KVM-DC02] -- specs --- DC02_SPECS[("`**CPU:** 2 vCPU
                                                        **RAM:** 8GB
                                                        **Storage:** 100GB
                                                        **OS:** Windows Server 2025
                                                        **Role:** Domain Controller`")]

    %% Styling
    class SRV01,SRV02 hosts
    classDef hosts fill:#f1c232,stroke:#000,color:#000
    class DB01,DC01,DC02,WEB01,WRK01,WRK02 vms
    classDef vms fill:#7ea6e0,stroke:#000,color:#000
    class SRV01_SPECS,SRV02_SPECS,DB01_SPECS,DC01_SPECS,DC02_SPECS,WEB01_SPECS,WRK01_SPECS,WRK02_SPECS specs
    classDef specs fill:#d3d3d3,stroke:#000,color:#000
Loading

Roles

Role Description
domain_creation Creates a new AD forest along with its domains and OUs
domain_join Joins computers to the domain
domain_user_configuration Manages domain user accounts_ and passwords
esxi_vm_deployment Deploys VMs on ESXi host
firewall_configuration Configures firewall rules
hostname_configuration Sets the hostname of Windows machines
hyper-v_configuration Installs Hyper-V and configures virtual switches
hyper-v_vm_deployment Deploys VMs on Hyper-V host
iis_deployment Installs and configures Internet Information Services (IIS)
local_user_configuration Manages local user accounts and passwords
ntp_configuration Configures NTP settings for time synchronization
region_configuration Sets regional and locale settings
system_configuration Applies system-wide settings
system_information Gather host information
windows_updates Performs Windows updates

Prerequisites

  1. OpenSSH Server installed on the targeted hosts. Alternatively, this can be installed via PowerShell:

    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  2. SSH Service enabled on the targeted hosts:

    Start-Service sshd
    Set-Service -Name sshd -StartupType 'Automatic'
  3. SSH allowed through the firewall:

    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Profile Any
  4. SSH connection verified once from the controller to each host:

    ssh administrator@<IP_ADDRESS>

    Accept the host key on first connection by typing yes when prompted.

Applying Configuration

  1. Update the inventory and variable files:
  • Update inventory.yml to define the Windows hosts.
  • Update domain_var.yml to define the domain configuration.
  • Update user_var.yml to define all domain users.
  • Update vm_var.yml to define the VMs and their specifications to be created and configured.
  • Update windows_var.yml to define environment-specific variables (e.g., usernames, passwords, hostnames, etc.)
  1. Start the Ansible environment:

    docker compose up -d
  2. Access the running Ansible container:

    docker exec -it ansible_service /bin/bash
  3. Execute the playbook to apply the settings:

    ansible-playbook site.yml -i inventory.yml

Tip

Use -t option to selectively run specific plays:

ansible-playbook site.yml -i inventory.yml -t system_information

Releases

No releases published

Packages

No packages published