Proxmox VM Deployment Automation
Create new VMs in Proxmox using VM Templates and Ansible in under 2 minutes.
This guide builds upon the previous Ansible tutorial, demonstrating how to leverage Proxmox and Ansible to create and deploy reusable Proxmox templates. This process reduces the time required to spin up a new VM, allowing you to have a ready-to-go machine in under two minutes.
Proxmox Template Creation
Download the Latest ISO Image:
- Navigate to
Storage > ISO Images > Download from URL
and download the latest LTS image for Ubuntu or the required distribution.
Create a VM to be Used as a Template:
- Create a VM as you usually would for a non-template VM:
- Set the VM's hardware settings and deploy the OS.
- Install the QEMU guest agent.
- Create an Ansible account and configure the SSH key.
- Remove the installation disk after setup.
- By default, Ubuntu uses Netplan to set DHCP without the MAC address, which means each new VM from the template will have the same IP as the original machine. To change this and issue a new IP to each new templated VM:
sudo nano /etc/netplan/50-cloud-init.yaml
- Add
dhcp-identifier: mac
underDHCP4: true
. - Save and exit.
- Shut down the VM completely.
Create the Template:
- Right-click on the VM and select
Create Template
.
Deploy a New VM:
- Right-click on the template and select
Clone
. - Choose
Mode: Full Clone
and set the desired name for the new VM.
Using Ansible for VM Setup
After deploying the new VM, you can optionally use Ansible to update the system, change the hostname, and install MeshCentral. The VM template is fully functional as-is, but for any additional configurations beyond the base setup, it is advisable to use Ansible.
Create an Ansible Inventory File
Ansible Playbooks
Create the individual YAML files for different tasks.
- Connectivity and Update Playbook (
new_update.yml
)
- MeshCentral Deployment Playbook (
new_meshcentral.yml
)
- Set Host Name Playbook (
new_hostname.yml
)
- Deploy Docker and Docker Compose (
new_docker.yml
)
Combine all the individual playbooks into a master playbook (new_machine_master.yml
):
Edit the Inventory File:
- Update the IP address in the
new_machine
inventory file:nano new_machine
- Execute the Master Playbook:
ansible-playbook -i new_machine new_machine_master.yml
Creating a New VM from a Template
Whenever a new VM is required, follow these steps to deploy one:
Clone the Template:
- Right-click on the Proxmox template and select
Clone
. - Choose
Mode: Full Clone
and set the desired name.
Get the New VM's IP:
- Wait for the VM to boot up and retrieve its IP address.
Update the Inventory File:
- Add the new IP address to the
servers
list in thenew_machine
inventory file on your Ansible machine:nano new_machine
- Run the Ansible Playbook:
ansible-playbook -i new_machine new_machine_master.yml
Feel free to tweak and expand on these examples as needed for your specific environment.