This is the second post for the ongoing home project and it contains the skeleton used for future deployments. Consider using Ansible Vault. The structure can change in the future, the goal is to avoid hardcoding and at a later stage implement CI/CD pipeline. This post provides a comprehensive guide to use Ansible for deploying, configuring, and managing both Windows and Linux virtual machines (VMs) on Proxmox VE. The shared codebase is a structured example of how to automate these processes use Ansible playbooks and roles. Below, we'll walk through the features, structure, and operation of this setup.
Updates:
- Template for Windows 10 with cloudbase.
- Template for Ubuntu 24.04 Server and Desktop with cloudinit.
- Added template for Windows Server 2019.
- Ansible Skeleton for VMs:
- Static inventory that is dynamically updated with the deployed hosts
- Roles for deploying Linux/Windows VMs and update hosts
- Roles for deleting VMs and update hosts
- Testing Provisioning for a windows VM
Key Features
- Dynamic Inventory Management:
- The VMs are assigned dynamic IPs via DHCP, which are then automatically added to a static inventory file (
hosts
). This automation simplifies future provisioning tasks. - VMs can be also deployed with static IP, cloudbase and cloudinit are install with packer.
- VMs are defined in vars_hosts.yaml. To add more VMs change the values. Each VM, lately, can be provisioned separatly.
- The VMs are assigned dynamic IPs via DHCP, which are then automatically added to a static inventory file (
- Template-Based VM Creation:
- VMs are created from existing templates, allowing for a standardized and quick deployment process.
- Templates can be customized to fit different bases, offering a wide range of configuration options.
- Flexible Role Structure:
- The roles are modular and easily expandable, making it simple to customize the setup for different deployment scenarios.
- Main focus - reusability.
How It Works
1. Deployment of VMs
- Playbook:
deploy_hosts.yaml
- This playbook handles the creation of VMs from pre-existing templates. VMs are deployed based on the lists
newid_values
andnewid_values_win
, each representing Linux and Windows VMs, respectively. The VMs are assigned IP addresses via DHCP, which are then dynamically added to thehosts
inventory file.
2. Configuration of VMs
- Playbook:
config_windows.yaml
- This playbook is used to provision Windows VMs post-deployment. The configuration tasks are defined in the role located at
roles/configure/windows/test
.
3. Deletion of VMs
- Playbook:
delete_hosts.yaml
- This playbook is used to delete VMs and remove their details from the
hosts
inventory file, ensuring the file remains current and accurate.
4. Inventory Management
- Inventory File:
hosts
- The
hosts
file is a static inventory that is dynamically updated with the IP addresses and hostnames of deployed VMs. This approach makes future tasks easier, as the VMs can be referenced directly by their hostnames or VM IDs.
Next -> Explore options for the frontend, execute this skeleton. Ideal, a tool that runs Ansible playbooks and has a fast way to implement and handle API connections for the deployed hosts and provides a easy way for configuring frontend visualization.