Auxiliary repository for my Dotfiles project, responsible for creating test VMs on Proxmox for my labs, providing a fast and more efficient way to set up environments.
This code was developed with the assumption that SPICE is used as the Proxmox console. Therefore, if you're using SPICE, it is necessary to install the following package on the Host Machine:
- virt-viewer
This code was written in Ansible, and works by using a external var and tags.
-
external_vars: Specifies the supported operating systems. The valid values are
- ubuntu
- arch
-
tags: Defines the operations you want to execute. The valid values are
- create
- post-install
- start
- stop
- destroy
The commands define the following execution flow:
This command is used to create a VM on Proxmox. After that, access the VM through the Proxmox GUI and use the regular installation wizard. Once the installation is complete, stop the VM and proceed with the next command.
This command is used to:
- Remove the ISO from VM's CDROM
- change the boot order to boot from disk
- Convert VM into a template
- Clone the template into a new VM.
At this point, manual steps must be executed inside the VM to ensure proper functionality. Run the following commands inside the VM:
sudo apt update && sudo apt upgrade -y
sudo apt install openssh-server qemu-guest-agent spice-vdagent -y
sudo systemctl status ssh qemu-guest-agent spice-vdagent
sudo systemctl start ssh qemu-guest-agent spice-vdagent
sudo systemctl enable ssh qemu-guest-agent spice-vdagent
After completing these steps, it is recommended to create a snapshot in Proxmox.
The start, stop, and destroy commands are control commands used to manage the VM lifecycle.
To execute the playbook with Ansibl:
- Set the
os_type_list
external variable to either "ubuntu" or "arch". - Adjust the tags to specify which commands to execute
ansible-playbook main.yaml -i hosts.yaml
--extra-vars "os_type_list=['ubuntu','arch']"
--tags "create"
To run the playbook using Docker, update the docker-compose.yml file:
- Update the command field with the correct Ansible command.
Once configured, run:
docker compose up && sleep 1 && docker compose down